home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / comm / term / term34Source.lha / termARexxCommands.c < prev    next >
C/C++ Source or Header  |  1993-07-16  |  98KB  |  5,629 lines

  1. /*
  2. **    termARexxCommands.c
  3. **
  4. **    ARexx interface command support routines
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termARexxGlobal.h"
  11.  
  12.     /* Number of bytes already processed by ScanNodeFilter(). */
  13.  
  14. STATIC LONG WaitCount = 0;
  15.  
  16.     /* Cheapo shortcuts ;-) */
  17.  
  18. #define Args    Pkt -> Array
  19. #define Results    Pkt -> Results
  20.  
  21.     /* ScanNodeFilter():
  22.      *
  23.      *    Scan memory for a certain sequence.
  24.      */
  25.  
  26. STATIC STRPTR __regargs
  27. ScanNodeFilter(register STRPTR Data,register LONG Size,register struct WaitNode *Node)
  28. {
  29.     register UBYTE c,Mask;
  30.  
  31.     if(Config -> SerialConfig -> StripBit8)
  32.         Mask = 0x7F;
  33.     else
  34.         Mask = 0xFF;
  35.  
  36.     if(Node)
  37.     {
  38.         do
  39.         {
  40.             if(c = ToUpper((*Data++) & Mask))
  41.             {
  42.                 register BYTE MatchMade;
  43.  
  44.                 do
  45.                 {
  46.                     MatchMade = FALSE;
  47.  
  48.                     if(Node -> Count == WaitCount)
  49.                     {
  50.                         if(c == Node -> Node . ln_Name[WaitCount] & Mask)
  51.                         {
  52.                             MatchMade = TRUE;
  53.  
  54.                             if(!Node -> Node . ln_Name[++Node -> Count])
  55.                                 return(Node -> Node . ln_Name);
  56.                         }
  57.                     }
  58.  
  59.                     if(MatchMade)
  60.                         WaitCount++;
  61.                     else
  62.                     {
  63.                         if(WaitCount)
  64.                         {
  65.                             WaitCount = 0;
  66.  
  67.                             Node -> Count = 0;
  68.                         }
  69.                         else
  70.                             break;
  71.                     }
  72.                 }
  73.                 while(!WaitCount);
  74.             }
  75.         }
  76.         while(--Size);
  77.     }
  78.     else
  79.     {
  80.         do
  81.         {
  82.             if(c = ToUpper((*Data++) & Mask))
  83.             {
  84.                 register BYTE MatchMade;
  85.  
  86.                 do
  87.                 {
  88.                     MatchMade = FALSE;
  89.  
  90.                     Node = (struct WaitNode *)GenericListTable[GLIST_WAIT] -> ListHeader . mlh_Head;
  91.  
  92.                     while(Node -> Node . ln_Succ)
  93.                     {
  94.                         if(Node -> Count == WaitCount)
  95.                         {
  96.                             if(c == Node -> Node . ln_Name[WaitCount] & Mask)
  97.                             {
  98.                                 Node -> Count++;
  99.  
  100.                                 MatchMade = TRUE;
  101.  
  102.                                 if(!Node -> Node . ln_Name[Node -> Count])
  103.                                     return(Node -> Node . ln_Name);
  104.                             }
  105.                         }
  106.  
  107.                         Node = (struct WaitNode *)Node -> Node . ln_Succ;
  108.                     }
  109.  
  110.                     if(MatchMade)
  111.                         WaitCount++;
  112.                     else
  113.                     {
  114.                         if(WaitCount)
  115.                         {
  116.                             WaitCount = 0;
  117.  
  118.                             Node = (struct WaitNode *)GenericListTable[GLIST_WAIT] -> ListHeader . mlh_Head;
  119.  
  120.                             while(Node -> Node . ln_Succ)
  121.                             {
  122.                                 Node -> Count = 0;
  123.  
  124.                                 Node = (struct WaitNode *)Node -> Node . ln_Succ;
  125.                             }
  126.                         }
  127.                         else
  128.                             break;
  129.                     }
  130.                 }
  131.                 while(!WaitCount);
  132.             }
  133.         }
  134.         while(--Size);
  135.     }
  136.  
  137.     return(NULL);
  138. }
  139.  
  140.     /* LocalRexxSerialCommandServer(VOID):
  141.      *
  142.      *    Asynchronous process to execute SerialCommand() style
  143.      *    ARexx commands.
  144.      */
  145.  
  146. STATIC VOID __saveds
  147. LocalRexxSerialCommandServer(VOID)
  148. {
  149.     struct Process    *ThisProcess = (struct Process *)SysBase -> ThisTask;
  150.     struct Message    *Message;
  151.     BPTR         OldCOS,
  152.              NewCOS    = NULL;
  153.     struct MsgPort    *RexxPort;
  154.  
  155.     WaitPort(&ThisProcess -> pr_MsgPort);
  156.  
  157.     Message = GetMsg(&ThisProcess -> pr_MsgPort);
  158.  
  159.     ObtainSemaphore(&RexxLaunchSemaphore);
  160.  
  161.     RexxLaunchCount++;
  162.  
  163.     ReleaseSemaphore(&RexxLaunchSemaphore);
  164.  
  165.     if(!ThisProcess -> pr_COS && ThisProcess -> pr_ConsoleTask)
  166.     {
  167.         if(NewCOS = Open("*",MODE_NEWFILE))
  168.         {
  169.             OldCOS = ThisProcess -> pr_COS;
  170.  
  171.             ThisProcess -> pr_COS = NewCOS;
  172.         }
  173.     }
  174.  
  175.     if(RexxPort = FindPort(RXSDIR))
  176.     {
  177.         struct MsgPort __aligned     SinglePort;
  178.         struct RexxMsg            *HostMessage;
  179.  
  180.         InitSinglePort(&SinglePort);
  181.  
  182.         if(HostMessage = CreateRexxMsg(&SinglePort,"term",RexxPortName))
  183.         {
  184.             if(HostMessage -> rm_Args[0] = CreateArgstring(Message -> mn_Node . ln_Name,strlen(Message -> mn_Node . ln_Name)))
  185.             {
  186.                 HostMessage -> rm_Action = RXCOMM;
  187.  
  188.                 if(!GoodStream(NULL))
  189.                     HostMessage -> rm_Action |= RXFF_NOIO;
  190.  
  191.                 Forbid();
  192.  
  193.                 PutMsg(RexxPort,HostMessage);
  194.  
  195.                 ClrSignal(SIGF_SINGLE);
  196.  
  197.                 WaitPort(&SinglePort);
  198.  
  199.                 Permit();
  200.  
  201.                 GetMsg(&SinglePort);
  202.             }
  203.  
  204.             DeleteRexxMsg(HostMessage);
  205.         }
  206.     }
  207.  
  208.     Forbid();
  209.  
  210.     ObtainSemaphore(&RexxLaunchSemaphore);
  211.  
  212.     RexxLaunchCount--;
  213.  
  214.     ReleaseSemaphore(&RexxLaunchSemaphore);
  215.  
  216.     if(NewCOS)
  217.     {
  218.         ThisProcess -> pr_COS = OldCOS;
  219.  
  220.         Close(NewCOS);
  221.     }
  222.  
  223.     ReplyMsg(Message);
  224. }
  225.  
  226.     /* LocalAmigaDOSSerialCommandServer(VOID):
  227.      *
  228.      *    Asynchronous process to execute SerialCommand() style
  229.      *    AmigaDOS commands.
  230.      */
  231.  
  232. STATIC VOID __saveds
  233. LocalAmigaDOSSerialCommandServer(VOID)
  234. {
  235.     struct Process    *ThisProcess = (struct Process *)SysBase -> ThisTask;
  236.     struct Message    *Message;
  237.     BPTR         OldCOS,
  238.              NewCOS    = NULL;
  239.  
  240.     WaitPort(&ThisProcess -> pr_MsgPort);
  241.  
  242.     Message = GetMsg(&ThisProcess -> pr_MsgPort);
  243.  
  244.     ObtainSemaphore(&RexxLaunchSemaphore);
  245.  
  246.     RexxLaunchCount++;
  247.  
  248.     ReleaseSemaphore(&RexxLaunchSemaphore);
  249.  
  250.     if(!ThisProcess -> pr_COS && ThisProcess -> pr_ConsoleTask)
  251.     {
  252.         if(NewCOS = Open("*",MODE_NEWFILE))
  253.         {
  254.             OldCOS = ThisProcess -> pr_COS;
  255.  
  256.             ThisProcess -> pr_COS = NewCOS;
  257.         }
  258.     }
  259.  
  260.     SystemTags(Message -> mn_Node . ln_Name,TAG_DONE);
  261.  
  262.     Forbid();
  263.  
  264.     ObtainSemaphore(&RexxLaunchSemaphore);
  265.  
  266.     RexxLaunchCount--;
  267.  
  268.     ReleaseSemaphore(&RexxLaunchSemaphore);
  269.  
  270.     if(NewCOS)
  271.     {
  272.         ThisProcess -> pr_COS = OldCOS;
  273.  
  274.         Close(NewCOS);
  275.     }
  276.  
  277.     ReplyMsg(Message);
  278. }
  279.  
  280.     /* LocalRexxSerialCommand(STRPTR Command,struct RexxPkt *Pkt):
  281.      *
  282.      *    Executes SerialCommand() style strings.
  283.      */
  284.  
  285. STATIC VOID __regargs
  286. LocalRexxSerialCommand(STRPTR Command,struct RexxPkt *Pkt)
  287. {
  288.     LONG Len = strlen(Command);
  289.  
  290.     if(Len)
  291.     {
  292.         BYTE    GotCommand = FALSE;
  293.         LONG    RexxIndex = -1,
  294.             AmigaDOSIndex = -1,
  295.             i;
  296.  
  297.             /* Check for embedded commands. */
  298.  
  299.         for(i = 0 ; i < Len ; i++)
  300.         {
  301.                 /* Found an escape symbol? */
  302.  
  303.             if(Command[i] == '\\')
  304.             {
  305.                     /* Is an ARexx command to be executed? */
  306.  
  307.                 switch(Command[i + 1])
  308.                 {
  309.                     case 'a':
  310.                     case 'A':
  311.                             /* Cut off the remaining string. */
  312.  
  313.                         Len = i;
  314.  
  315.                             /* Remember where to look for the rexx command. */
  316.  
  317.                         RexxIndex = i + 2;
  318.  
  319.                             /* Skip blanks. */
  320.  
  321.                         while((Command[RexxIndex] == '\t' || Command[RexxIndex] == ' ') && Command[RexxIndex])
  322.                             RexxIndex++;
  323.  
  324.                             /* No remaining data? */
  325.  
  326.                         if(!Command[RexxIndex])
  327.                             RexxIndex = -1;
  328.  
  329.                         break;
  330.  
  331.                     case 'd':
  332.                     case 'D':
  333.                             /* Cut off the remaining string. */
  334.  
  335.                         Len = i;
  336.  
  337.                             /* Remember where to look for the rexx command. */
  338.  
  339.                         AmigaDOSIndex = i + 2;
  340.  
  341.                             /* Skip blanks. */
  342.  
  343.                         while((Command[AmigaDOSIndex] == '\t' || Command[AmigaDOSIndex] == ' ') && Command[AmigaDOSIndex])
  344.                             AmigaDOSIndex++;
  345.  
  346.                             /* No remaining data? */
  347.  
  348.                         if(!Command[AmigaDOSIndex])
  349.                             AmigaDOSIndex = -1;
  350.  
  351.                         break;
  352.  
  353.                     default:
  354.  
  355.                         GotCommand = TRUE;
  356.                         break;
  357.                 }
  358.             }
  359.             else
  360.             {
  361.                     /* Found an escape symbol? */
  362.  
  363.                 if(Command[i] == '^')
  364.                     GotCommand = TRUE;
  365.             }
  366.         }
  367.  
  368.             /* Any text to be processed? */
  369.  
  370.         if(Len)
  371.         {
  372.                 /* Found a command? */
  373.  
  374.             if(GotCommand)
  375.             {
  376.                 STRPTR Buffer;
  377.  
  378.                     /* Allocate a temporary buffer. */
  379.  
  380.                 if(Buffer = (STRPTR)AllocVec(Len + 1,MEMF_ANY))
  381.                 {
  382.                         /* Copy the buffer. */
  383.  
  384.                     CopyMem(Command,Buffer,Len);
  385.  
  386.                         /* Null-terminate it. */
  387.  
  388.                     Buffer[Len] = 0;
  389.  
  390.                         /* Execute the commands. */
  391.  
  392.                     SerialCommand(Buffer);
  393.  
  394.                         /* Release the temporary buffers. */
  395.  
  396.                     FreeVec(Buffer);
  397.                 }
  398.                 else
  399.                 {
  400.                     if(Pkt)
  401.                     {
  402.                         Results[0] = RC_ERROR;
  403.                         Results[1] = ERROR_NO_FREE_STORE;
  404.                     }
  405.                 }
  406.             }
  407.             else
  408.                 (*SendLine)(Command,Len);
  409.         }
  410.  
  411.             /* Are we to execute any embedded ARexx commands? */
  412.  
  413.         if(RexxIndex != -1)
  414.         {
  415.             struct Message *Message;
  416.  
  417.                 /* Move up in the string. */
  418.  
  419.             Command += RexxIndex;
  420.  
  421.                 /* Determine remaining length. */
  422.  
  423.             Len = strlen(Command);
  424.  
  425.                 /* Allocate command message. */
  426.  
  427.             if(Message = (struct Message *)AllocVec(sizeof(struct Message) + Len + 1,MEMF_ANY | MEMF_PUBLIC | MEMF_CLEAR))
  428.             {
  429.                 struct Process    *NewProcess;
  430.                 BPTR         Stream;
  431.  
  432.                     /* Initialize the message. */
  433.  
  434.                 Message -> mn_Node . ln_Name    = (STRPTR)(Message + 1);
  435.                 Message -> mn_ReplyPort        = RexxPort;
  436.                 Message -> mn_Length        = sizeof(struct Message) + Len + 1;
  437.  
  438.                 strcpy(Message -> mn_Node . ln_Name,Command);
  439.  
  440.                     /* Open proper output stream. */
  441.  
  442.                 if(WindowName[0])
  443.                     Stream = Open(WindowName,MODE_NEWFILE);
  444.                 else
  445.                     Stream = NULL;
  446.  
  447.                     /* Spawn the server process. */
  448.  
  449.                 if(Stream && GoodStream(Stream))
  450.                 {
  451.                     struct FileHandle *Handle = (struct FileHandle *)BADDR(Stream);
  452.  
  453.                     NewProcess = CreateNewProcTags(
  454.                         NP_Entry,    LocalRexxSerialCommandServer,
  455.                         NP_Input,    Stream,
  456.                         NP_Output,    NULL,
  457.                         NP_ConsoleTask,    Handle -> fh_Type,
  458.                         NP_StackSize,    8000,
  459.                         NP_Name,    "term Rexx serial command process",
  460.                         NP_Cli,        TRUE,
  461.                     TAG_DONE);
  462.                 }
  463.                 else
  464.                 {
  465.                     NewProcess = CreateNewProcTags(
  466.                         NP_Entry,    LocalRexxSerialCommandServer,
  467.                         NP_StackSize,    8000,
  468.                         NP_ConsoleTask,    NULL,
  469.                         NP_Name,    "term Rexx serial command process",
  470.                         NP_Cli,        TRUE,
  471.                     TAG_DONE);
  472.                 }
  473.  
  474.                     /* Send the command message. */
  475.  
  476.                 if(NewProcess)
  477.                     PutMsg(&NewProcess -> pr_MsgPort,Message);
  478.                 else
  479.                 {
  480.                     if(Pkt)
  481.                     {
  482.                         Results[0] = RC_ERROR;
  483.                         Results[1] = IoErr();
  484.                     }
  485.  
  486.                     FreeVec(Message);
  487.  
  488.                     if(Stream)
  489.                         Close(Stream);
  490.                 }
  491.             }
  492.             else
  493.             {
  494.                 if(Pkt)
  495.                 {
  496.                     Results[0] = RC_ERROR;
  497.                     Results[1] = ERROR_NO_FREE_STORE;
  498.                 }
  499.             }
  500.         }
  501.  
  502.             /* Are we to execute an embedded AmigaDOS command? */
  503.  
  504.         if(AmigaDOSIndex != -1)
  505.         {
  506.             struct Message *Message;
  507.  
  508.                 /* Move up in the string. */
  509.  
  510.             Command += AmigaDOSIndex;
  511.  
  512.                 /* Determine remaining length. */
  513.  
  514.             Len = strlen(Command);
  515.  
  516.                 /* Allocate command message. */
  517.  
  518.             if(Message = (struct Message *)AllocVec(sizeof(struct Message) + Len + 1,MEMF_ANY | MEMF_PUBLIC | MEMF_CLEAR))
  519.             {
  520.                 struct Process    *NewProcess;
  521.                 BPTR         Stream;
  522.  
  523.                     /* Initialize the message. */
  524.  
  525.                 Message -> mn_Node . ln_Name    = (STRPTR)(Message + 1);
  526.                 Message -> mn_ReplyPort        = RexxPort;
  527.                 Message -> mn_Length        = sizeof(struct Message) + Len + 1;
  528.  
  529.                 strcpy(Message -> mn_Node . ln_Name,Command);
  530.  
  531.                     /* Open proper output stream. */
  532.  
  533.                 if(WindowName[0])
  534.                     Stream = Open(WindowName,MODE_NEWFILE);
  535.                 else
  536.                     Stream = NULL;
  537.  
  538.                     /* Spawn the server process. */
  539.  
  540.                 if(Stream && GoodStream(Stream))
  541.                 {
  542.                     struct FileHandle *Handle = (struct FileHandle *)BADDR(Stream);
  543.  
  544.                     NewProcess = CreateNewProcTags(
  545.                         NP_Entry,    LocalAmigaDOSSerialCommandServer,
  546.                         NP_Input,    Stream,
  547.                         NP_Output,    NULL,
  548.                         NP_ConsoleTask,    Handle -> fh_Type,
  549.                         NP_StackSize,    8000,
  550.                         NP_Name,    "term AmigaDOS serial command process",
  551.                         NP_Cli,        TRUE,
  552.                     TAG_DONE);
  553.                 }
  554.                 else
  555.                 {
  556.                     NewProcess = CreateNewProcTags(
  557.                         NP_Entry,    LocalAmigaDOSSerialCommandServer,
  558.                         NP_StackSize,    8000,
  559.                         NP_ConsoleTask,    NULL,
  560.                         NP_Name,    "term AmigaDOS serial command process",
  561.                         NP_Cli,        TRUE,
  562.                     TAG_DONE);
  563.                 }
  564.  
  565.                     /* Send the command message. */
  566.  
  567.                 if(NewProcess)
  568.                     PutMsg(&NewProcess -> pr_MsgPort,Message);
  569.                 else
  570.                 {
  571.                     if(Pkt)
  572.                     {
  573.                         Results[0] = RC_ERROR;
  574.                         Results[1] = IoErr();
  575.                     }
  576.  
  577.                     if(Stream)
  578.                         Close(Stream);
  579.  
  580.                     FreeVec(Message);
  581.                 }
  582.             }
  583.             else
  584.             {
  585.                 if(Pkt)
  586.                 {
  587.                     Results[0] = RC_ERROR;
  588.                     Results[1] = ERROR_NO_FREE_STORE;
  589.                 }
  590.             }
  591.         }
  592.     }
  593. }
  594.  
  595. STRPTR __regargs
  596. RexxActivate(struct RexxPkt *Pkt)
  597. {
  598.     if(Window)
  599.         BumpWindow(Window);
  600.     else
  601.     {
  602.         if(!IconTerminated)
  603.             IconTerminated = TRUE;
  604.     }
  605.  
  606.     return(NULL);
  607. }
  608.  
  609. STRPTR __regargs
  610. RexxAdd(struct RexxPkt *Pkt)
  611. {
  612.     enum    {    ARG_ADD_FROM,ARG_ADD_BEFORE,ARG_ADD_AFTER,ARG_ADD_PHONEENTRY,
  613.             ARG_ADD_NAME };
  614.  
  615.     WORD ListIndex;
  616.  
  617.     if((ListIndex = ToList(Args[ARG_ADD_FROM])) != -1)
  618.     {
  619.         struct GenericList    *List = GenericListTable[ListIndex];
  620.         BYTE             AddMode;
  621.  
  622.         if(Args[ARG_ADD_BEFORE])
  623.             AddMode = ADD_GLIST_BEFORE;
  624.         else
  625.         {
  626.             if(Args[ARG_ADD_AFTER])
  627.                 AddMode = ADD_GLIST_BEHIND;
  628.             else
  629.                 AddMode = ADD_GLIST_BOTTOM;
  630.         }
  631.  
  632.         if(ListIndex == GLIST_DIAL)
  633.         {
  634.             if(Args[ARG_ADD_PHONEENTRY])
  635.             {
  636.                 if(!IsNumeric(Args[ARG_ADD_PHONEENTRY]))
  637.                 {
  638.                     STRPTR Buffer;
  639.  
  640.                     if(Buffer = CreateMatchBuffer(Args[ARG_ADD_PHONEENTRY]))
  641.                     {
  642.                         struct DialNode    *Node;
  643.                         LONG         i;
  644.  
  645.                         for(i = 0 ; i < NumPhoneEntries ; i++)
  646.                         {
  647.                             if(MatchBuffer(Buffer,Phonebook[i] -> Header -> Name))
  648.                             {
  649.                                 if(Node = (struct DialNode *)CreateGenericListNode(sizeof(struct DialNode),NULL))
  650.                                 {
  651.                                     Node -> Entry = Phonebook[i];
  652.  
  653.                                     AddGenericListNode(List,(struct Node *)Node,AddMode);
  654.                                 }
  655.                                 else
  656.                                 {
  657.                                     Results[0] = RC_ERROR;
  658.                                     Results[1] = ERROR_NO_FREE_STORE;
  659.  
  660.                                     break;
  661.                                 }
  662.                             }
  663.                         }
  664.  
  665.                         DeleteMatchBuffer(Buffer);
  666.                     }
  667.                     else
  668.                     {
  669.                         Results[0] = RC_ERROR;
  670.                         Results[1] = ERROR_NO_FREE_STORE;
  671.                     }
  672.                 }
  673.                 else
  674.                 {
  675.                     LONG Index = Atol(Args[ARG_ADD_PHONEENTRY]);
  676.  
  677.                     if(Index < 0 || Index > NumPhoneEntries)
  678.                     {
  679.                         Results[0] = RC_ERROR;
  680.                         Results[1] = TERMERROR_INDEX_OUT_OF_RANGE;
  681.                     }
  682.                     else
  683.                     {
  684.                         struct DialNode    *Node;
  685.  
  686.                         if(Node = (struct DialNode *)CreateGenericListNode(sizeof(struct DialNode),NULL))
  687.                         {
  688.                             Node -> Entry = Phonebook[Index];
  689.  
  690.                             AddGenericListNode(List,(struct Node *)Node,AddMode);
  691.                         }
  692.                         else
  693.                         {
  694.                             Results[0] = RC_ERROR;
  695.                             Results[1] = ERROR_NO_FREE_STORE;
  696.                         }
  697.                     }
  698.                 }
  699.             }
  700.             else
  701.             {
  702.                 if(Args[ARG_ADD_NAME])
  703.                 {
  704.                     struct Node *Node;
  705.  
  706.                     if(Node = CreateGenericListNode(sizeof(struct DialNode),Args[ARG_ADD_NAME]))
  707.                         AddGenericListNode(List,Node,AddMode);
  708.                     else
  709.                     {
  710.                         Results[0] = RC_ERROR;
  711.                         Results[1] = ERROR_NO_FREE_STORE;
  712.                     }
  713.                 }
  714.             }
  715.         }
  716.         else
  717.         {
  718.             if(Args[ARG_ADD_NAME])
  719.             {
  720.                 struct Node *Node;
  721.  
  722.                 if(Node = CreateGenericListNode(sizeof(struct DialNode),Args[ARG_ADD_NAME]))
  723.                 {
  724.                     if(ListIndex == GLIST_WAIT)
  725.                     {
  726.                         WORD i;
  727.  
  728.                         for(i = 0 ; i < strlen(Node -> ln_Name) ; i++)
  729.                             Node -> ln_Name[i] = ToUpper(Node -> ln_Name[i]);
  730.                     }
  731.  
  732.                     AddGenericListNode(List,Node,AddMode);
  733.                 }
  734.                 else
  735.                 {
  736.                     Results[0] = RC_ERROR;
  737.                     Results[1] = ERROR_NO_FREE_STORE;
  738.                 }
  739.             }
  740.             else
  741.             {
  742.                 Results[0] = RC_ERROR;
  743.                 Results[1] = TERMERROR_WRONG_LIST;
  744.             }
  745.         }
  746.     }
  747.     else
  748.     {
  749.         Results[0] = RC_ERROR;
  750.         Results[1] = TERMERROR_UNKNOWN_LIST;
  751.     }
  752.  
  753.     return(NULL);
  754. }
  755.  
  756. STRPTR __regargs
  757. RexxBaud(struct RexxPkt *Pkt)
  758. {
  759.     enum    {    ARG_BAUD_RATE };
  760.  
  761.     LONG Rate = *(LONG *)Args[ARG_BAUD_RATE],Min = MILLION,Diff,Index;
  762.     WORD i;
  763.  
  764.     for(i = 0 ; i < NumBaudRates ; i++)
  765.     {
  766.         Diff = Rate - BaudRates[i];
  767.  
  768.         if(Diff >= 0 && Diff < Min)
  769.         {
  770.             Min    = Diff;
  771.             Index    = i;
  772.         }
  773.     }
  774.  
  775.     if(BaudRates[Index] != Config -> SerialConfig -> BaudRate)
  776.     {
  777.         Config -> SerialConfig -> BaudRate = BaudRates[Index];
  778.  
  779.         ConfigChanged = TRUE;
  780.  
  781.         UpdateRequired = TRUE;
  782.     }
  783.  
  784.     return(NULL);
  785. }
  786.  
  787. STRPTR __regargs
  788. RexxBeepScreen(struct RexxPkt *Pkt)
  789. {
  790.     DoBeep();
  791.  
  792.     return(NULL);
  793. }
  794.  
  795. STRPTR __regargs
  796. RexxCallMenu(struct RexxPkt *Pkt)
  797. {
  798.     enum    {    ARG_CALLMENU_TITLE };
  799.  
  800.     STRPTR Buffer;
  801.  
  802.     if(Buffer = CreateMatchBuffer(Args[ARG_CALLMENU_TITLE]))
  803.     {
  804.         WORD i;
  805.  
  806.         Results[0] = RC_WARN;
  807.  
  808.             /* Scan the menu list... */
  809.  
  810.         for(i = 0 ; TermMenu[i] . nm_Type != NM_END ; i++)
  811.         {
  812.                 /* Did we get a valid name string? */
  813.  
  814.             if(TermMenu[i] . nm_Label != NM_BARLABEL)
  815.             {
  816.                     /* Does the name match our template? */
  817.  
  818.                 if(MatchBuffer(Buffer,TermMenu[i] . nm_Label))
  819.                 {
  820.                     HandleMenuCode((ULONG)TermMenu[i] . nm_UserData,NULL);
  821.  
  822.                     Results[0] = RC_OK;
  823.  
  824.                     break;
  825.                 }
  826.             }
  827.         }
  828.  
  829.         DeleteMatchBuffer(Buffer);
  830.     }
  831.     else
  832.     {
  833.         Results[0] = RC_ERROR;
  834.         Results[1] = ERROR_NO_FREE_STORE;
  835.     }
  836.  
  837.     return(NULL);
  838. }
  839.  
  840. STRPTR __regargs
  841. RexxCapture(struct RexxPkt *Pkt)
  842. {
  843.     enum    {    ARG_CAPTURE_TO,ARG_CAPTURE_NAME };
  844.  
  845.     if(!Stricmp(Args[ARG_CAPTURE_TO],"PRINTER"))
  846.     {
  847.         if(!PrinterCapture)
  848.             OpenPrinterCapture(FALSE);
  849.     }
  850.     else
  851.     {
  852.         if(!Stricmp(Args[ARG_CAPTURE_TO],"FILE"))
  853.         {
  854.             if(FileCapture)
  855.             {
  856.                 Results[0] = RC_ERROR;
  857.                 Results[1] = ERROR_OBJECT_IN_USE;
  858.             }
  859.             else
  860.             {
  861.                 if(Args[ARG_CAPTURE_NAME])
  862.                 {
  863.                     if(FileCapture = BufferOpen(Args[ARG_CAPTURE_NAME],"a"))
  864.                         strcpy(CaptureName,Args[ARG_CAPTURE_NAME]);
  865.                     else
  866.                     {
  867.                         Results[0] = RC_ERROR;
  868.                         Results[1] = IoErr();
  869.                     }
  870.                 }
  871.                 else
  872.                 {
  873.                     UBYTE             DummyBuffer[MAX_FILENAME_LENGTH],
  874.                                 *DummyChar;
  875.                     struct FileRequester    *FileRequest;
  876.  
  877.                     if(!CaptureName[0])
  878.                     {
  879.                         strcpy(CaptureName,Config -> CaptureConfig -> CapturePath);
  880.  
  881.                         if(!AddPart(CaptureName,LocaleString(MSG_DIALPANEL_CAPTURE_NAME_TXT),MAX_FILENAME_LENGTH))
  882.                             CaptureName[0] = 0;
  883.                     }
  884.  
  885.                     strcpy(DummyBuffer,CaptureName);
  886.  
  887.                     DummyChar = PathPart(DummyBuffer);
  888.  
  889.                     *DummyChar = 0;
  890.  
  891.                     BlockWindows();
  892.  
  893.                     if(FileRequest = GetFile(LocaleString(MSG_TERMMAIN_CAPTURE_TO_DISK_TXT),DummyBuffer,FilePart(CaptureName),DummyBuffer,NULL,TRUE,FALSE,FALSE,LocaleString(MSG_GLOBAL_OPEN_TXT),FALSE))
  894.                     {
  895.                         BYTE Continue;
  896.  
  897.                         if(GetFileSize(DummyBuffer))
  898.                         {
  899.                             Continue = TRUE;
  900.  
  901.                             switch(MyEasyRequest(Window,LocaleString(MSG_GLOBAL_FILE_ALREADY_EXISTS_TXT),LocaleString(MSG_GLOBAL_CREATE_APPEND_CANCEL_TXT),DummyBuffer))
  902.                             {
  903.                                 case 1:
  904.  
  905.                                     FileCapture = BufferOpen(DummyBuffer,"w");
  906.                                     break;
  907.  
  908.                                 case 2:
  909.  
  910.                                     FileCapture = BufferOpen(DummyBuffer,"a");
  911.                                     break;
  912.  
  913.                                 case 0:
  914.  
  915.                                     Results[0] = RC_WARN;
  916.                                     Continue = FALSE;
  917.                                     break;
  918.                             }
  919.                         }
  920.                         else
  921.                         {
  922.                             Continue = TRUE;
  923.  
  924.                             FileCapture = BufferOpen(DummyBuffer,"w");
  925.                         }
  926.  
  927.                         if(Continue)
  928.                         {
  929.                             if(!FileCapture)
  930.                             {
  931.                                 MyEasyRequest(Window,LocaleString(MSG_GLOBAL_ERROR_OPENING_FILE_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),DummyBuffer);
  932.  
  933.                                 Results[0] = RC_ERROR;
  934.                                 Results[1] = IoErr();
  935.                             }
  936.                             else
  937.                             {
  938.                                 strcpy(CaptureName,DummyBuffer);
  939.  
  940.                                 CheckItem(MEN_CAPTURE_TO_FILE,TRUE);
  941.                             }
  942.                         }
  943.  
  944.                         FreeAslRequest(FileRequest);
  945.                     }
  946.  
  947.                     ReleaseWindows();
  948.                 }
  949.             }
  950.         }
  951.         else
  952.         {
  953.             Results[0] = RC_ERROR;
  954.             Results[1] = ERROR_REQUIRED_ARG_MISSING;
  955.         }
  956.     }
  957.  
  958.     ConOutputUpdate();
  959.  
  960.     return(NULL);
  961. }
  962.  
  963. STRPTR __regargs
  964. RexxClear(struct RexxPkt *Pkt)
  965. {
  966.     enum    {    ARG_CLEAR_FROM,ARG_CLEAR_FORCE };
  967.  
  968.     if(!Stricmp(Args[ARG_CLEAR_FROM],"BUFFER"))
  969.     {
  970.         if(Lines)
  971.         {
  972.             if(Args[ARG_CLEAR_FORCE])
  973.             {
  974.                 FreeBuffer();
  975.  
  976.                 TerminateBuffer();
  977.             }
  978.             else
  979.             {
  980.                 BlockWindows();
  981.  
  982.                 if(MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_BUFFER_STILL_HOLDS_LINES_TXT),LocaleString(MSG_GLOBAL_YES_NO_TXT),Lines))
  983.                 {
  984.                     FreeBuffer();
  985.  
  986.                     TerminateBuffer();
  987.                 }
  988.                 else
  989.                     Results[0] = RC_WARN;
  990.  
  991.                 ReleaseWindows();
  992.             }
  993.         }
  994.     }
  995.     else
  996.     {
  997.         WORD ListIndex;
  998.  
  999.         if((ListIndex = ToList(Args[ARG_CLEAR_FROM])) != -1)
  1000.             ClearGenericList(GenericListTable[ListIndex]);
  1001.         else
  1002.         {
  1003.             Results[0] = RC_ERROR;
  1004.             Results[1] = TERMERROR_UNKNOWN_LIST;
  1005.         }
  1006.     }
  1007.  
  1008.     return(NULL);
  1009. }
  1010.  
  1011. STRPTR __regargs
  1012. RexxClearScreen(struct RexxPkt *Pkt)
  1013. {
  1014.     if(XEmulatorBase && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  1015.         XEmulatorClearConsole(XEM_IO);
  1016.     else
  1017.     {
  1018.         DropMarker();
  1019.  
  1020.         ClearCursor();
  1021.  
  1022.         EraseScreen("2J");
  1023.  
  1024.         SetAbsolutePosition("H");
  1025.  
  1026.         DrawCursor();
  1027.     }
  1028.  
  1029.     return(NULL);
  1030. }
  1031.  
  1032. STRPTR __regargs
  1033. RexxClose(struct RexxPkt *Pkt)
  1034. {
  1035.     enum    {    ARG_CLOSE_FROM };
  1036.  
  1037.     STATIC STRPTR ValidArgs[3] =
  1038.     {
  1039.         "PRINTER",
  1040.         "FILE",
  1041.         "ALL"
  1042.     };
  1043.  
  1044.     WORD i;
  1045.  
  1046.     for(i = 0 ; i < 3 ; i++)
  1047.     {
  1048.         if(!Stricmp(Args[ARG_CLOSE_FROM],ValidArgs[i]))
  1049.         {
  1050.             if(i == 0 || i == 2)
  1051.             {
  1052.                 if(PrinterCapture)
  1053.                     ClosePrinterCapture(TRUE);
  1054.             }
  1055.  
  1056.             if(i == 1 || i == 2)
  1057.             {
  1058.                 if(FileCapture)
  1059.                 {
  1060.                     BufferClose(FileCapture);
  1061.  
  1062.                     CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  1063.  
  1064.                     FileCapture = NULL;
  1065.  
  1066.                     if(!GetFileSize(CaptureName))
  1067.                         DeleteFile(CaptureName);
  1068.                     else
  1069.                     {
  1070.                         AddProtection(CaptureName,FIBF_EXECUTE);
  1071.  
  1072.                         if(Config -> MiscConfig -> CreateIcons)
  1073.                             AddIcon(CaptureName,FILETYPE_TEXT,TRUE);
  1074.                     }
  1075.  
  1076.                     ConOutputUpdate();
  1077.                 }
  1078.             }
  1079.  
  1080.             return(NULL);
  1081.         }
  1082.     }
  1083.  
  1084.     Results[0] = RC_ERROR;
  1085.     Results[1] = ERROR_TOO_MANY_ARGS;
  1086.  
  1087.     return(NULL);
  1088. }
  1089.  
  1090. STRPTR __regargs
  1091. RexxCloseDevice(struct RexxPkt *Pkt)
  1092. {
  1093.     ClearSerial();
  1094.  
  1095.     DeleteSerial();
  1096.  
  1097.     return(NULL);
  1098. }
  1099.  
  1100. STRPTR __regargs
  1101. RexxCloseRequester(struct RexxPkt *Pkt)
  1102. {
  1103.     if(ThisProcess)
  1104.         Signal(ThisProcess,SIG_BREAK);
  1105.     else
  1106.         Results[0] = RC_WARN;
  1107.  
  1108.     return(NULL);
  1109. }
  1110.  
  1111. STRPTR __regargs
  1112. RexxDeactivate(struct RexxPkt *Pkt)
  1113. {
  1114.     if(Window)
  1115.         DoIconify = TRUE;
  1116.  
  1117.     return(NULL);
  1118. }
  1119.  
  1120. STRPTR __regargs
  1121. RexxDial(struct RexxPkt *Pkt)
  1122. {
  1123.     enum    {    ARG_DIAL_NUM };
  1124.  
  1125.     struct PhoneNode    *DialNode;
  1126.     struct GenericList    *List;
  1127.  
  1128.     if(Args[ARG_DIAL_NUM])
  1129.     {
  1130.         struct List *LocalList;
  1131.  
  1132.         if(LocalList = (struct List *)AllocVec(sizeof(struct List),MEMF_ANY))
  1133.         {
  1134.             LONG Len = strlen(Args[ARG_DIAL_NUM]);
  1135.  
  1136.             NewList(LocalList);
  1137.  
  1138.             if(DialNode = (struct PhoneNode *)AllocVec(sizeof(struct PhoneNode) + Len + 1,MEMF_ANY | MEMF_CLEAR))
  1139.             {
  1140.                 DialNode -> VanillaNode . ln_Name = (STRPTR)(DialNode + 1);
  1141.  
  1142.                 strcpy(DialNode -> VanillaNode . ln_Name,Args[ARG_DIAL_NUM]);
  1143.  
  1144.                 AddTail(LocalList,&DialNode -> VanillaNode);
  1145.  
  1146.                 FreeDialList(TRUE);
  1147.  
  1148.                 DialList = LocalList;
  1149.             }
  1150.             else
  1151.             {
  1152.                 FreeVec(LocalList);
  1153.  
  1154.                 Results[0] = RC_ERROR;
  1155.                 Results[1] = ERROR_NO_FREE_STORE;
  1156.  
  1157.                 return(NULL);
  1158.             }
  1159.         }
  1160.     }
  1161.     else
  1162.     {
  1163.         if(GenericListCount(List = GenericListTable[GLIST_DIAL]))
  1164.         {
  1165.             struct DialNode *Node = (struct DialNode *)FirstGenericListNode(List);
  1166.  
  1167.             if(Node)
  1168.             {
  1169.                 LONG Len;
  1170.  
  1171.                 if(!DialList)
  1172.                 {
  1173.                     if(DialList = (struct List *)AllocVec(sizeof(struct List),MEMF_ANY | MEMF_CLEAR))
  1174.                         NewList(DialList);
  1175.                 }
  1176.  
  1177.                 if(DialList)
  1178.                 {
  1179.                     while(Node)
  1180.                     {
  1181.                         if(Node -> Entry)
  1182.                             Len = 0;
  1183.                         else
  1184.                             Len = strlen(Node -> Node . ln_Name) + 1;
  1185.  
  1186.                         if(DialNode = (struct PhoneNode *)AllocVec(sizeof(struct PhoneNode) + Len,MEMF_ANY | MEMF_CLEAR))
  1187.                         {
  1188.                             if(Node -> Entry)
  1189.                                 DialNode -> Entry = Node -> Entry;
  1190.                             else
  1191.                             {
  1192.                                 DialNode -> VanillaNode . ln_Name = (STRPTR)(DialNode + 1);
  1193.  
  1194.                                 strcpy(DialNode -> VanillaNode . ln_Name,Node -> Node . ln_Name);
  1195.                             }
  1196.  
  1197.                             AddTail(DialList,&DialNode -> VanillaNode);
  1198.                         }
  1199.                         else
  1200.                         {
  1201.                             FreeDialList(FALSE);
  1202.  
  1203.                             Results[0] = RC_ERROR;
  1204.                             Results[1] = ERROR_NO_FREE_STORE;
  1205.  
  1206.                             return(NULL);
  1207.                         }
  1208.  
  1209.                         Node = (struct DialNode *)NextGenericListNode(List);
  1210.                     }
  1211.                 }
  1212.             }
  1213.         }
  1214.     }
  1215.  
  1216.     if(DialList)
  1217.     {
  1218.         if(DialList -> lh_Head -> ln_Succ)
  1219.             DoDial = DIAL_LIST;
  1220.         else
  1221.         {
  1222.             FreeDialList(FALSE);
  1223.  
  1224.             Results[0] = RC_ERROR;
  1225.             Results[1] = TERMERROR_LIST_IS_ALREADY_EMPTY;
  1226.         }
  1227.     }
  1228.     else
  1229.     {
  1230.         Results[0] = RC_ERROR;
  1231.         Results[1] = ERROR_NO_FREE_STORE;
  1232.     }
  1233.  
  1234.     return(NULL);
  1235. }
  1236.  
  1237. STRPTR __regargs
  1238. RexxDelay(struct RexxPkt *Pkt)
  1239. {
  1240.     enum    {    ARG_DELAY_MICROSECONDS,ARG_DELAY_SECONDS,ARG_DELAY_MINUTES,ARG_DELAY_QUIET };
  1241.  
  1242.     LONG    Seconds = 0,
  1243.         Micros;
  1244.     ULONG    Signals;
  1245.     BYTE    Quiet;
  1246.  
  1247.     if(Args[ARG_DELAY_QUIET] || !ReadRequest || !WriteRequest)
  1248.         Quiet = TRUE;
  1249.     else
  1250.         Quiet = FALSE;
  1251.  
  1252.     if(Args[ARG_DELAY_MINUTES])
  1253.         Seconds += 60 * (*(LONG *)Args[ARG_DELAY_MINUTES]);
  1254.  
  1255.     if(Args[ARG_DELAY_SECONDS])
  1256.         Seconds += *(LONG *)Args[ARG_DELAY_SECONDS];
  1257.  
  1258.     if(Args[ARG_DELAY_MICROSECONDS])
  1259.         Micros = *(LONG *)Args[ARG_DELAY_MICROSECONDS];
  1260.     else
  1261.         Micros = 0;
  1262.  
  1263.     if(Seconds || Micros)
  1264.     {
  1265.         StartTime(Seconds,Micros);
  1266.  
  1267.         BlockWindows();
  1268.  
  1269.         if(Marking)
  1270.             DropMarker();
  1271.  
  1272.         ClearCursor();
  1273.  
  1274.         if(Quiet)
  1275.             Signals = NULL;
  1276.         else
  1277.         {
  1278.             if(DataHold)
  1279.             {
  1280.                 if(DataSize > 0)
  1281.                 {
  1282.                     ConProcess(DataHold,DataSize);
  1283.  
  1284.                     Status = STATUS_READY;
  1285.                 }
  1286.  
  1287.                 DataHold = NULL;
  1288.  
  1289.                 RestartSerial();
  1290.             }
  1291.  
  1292.             Signals = CheckSignal(SIG_SERIAL);
  1293.         }
  1294.  
  1295.         FOREVER
  1296.         {
  1297.             if(Signals & SIG_SERIAL)
  1298.             {
  1299.                 if(!WaitIO(ReadRequest))
  1300.                 {
  1301.                     LONG Length;
  1302.  
  1303.                     BytesIn++;
  1304.  
  1305.                     ConProcess(ReadBuffer,1);
  1306.  
  1307.                     Status = STATUS_READY;
  1308.  
  1309.                         /* Check how many bytes are still in
  1310.                          * the serial buffer.
  1311.                          */
  1312.  
  1313.                     WriteRequest -> IOSer . io_Command = SDCMD_QUERY;
  1314.  
  1315.                     DoIO(WriteRequest);
  1316.  
  1317.                     if(Length = WriteRequest -> IOSer . io_Actual)
  1318.                     {
  1319.                         if(Length > Config -> SerialConfig -> SerialBufferSize)
  1320.                             Length = Config -> SerialConfig -> SerialBufferSize;
  1321.  
  1322.                         if(Length > Config -> SerialConfig -> Quantum)
  1323.                             Length = Config -> SerialConfig -> Quantum;
  1324.  
  1325.                         ReadRequest -> IOSer . io_Command    = CMD_READ;
  1326.                         ReadRequest -> IOSer . io_Data        = ReadBuffer;
  1327.                         ReadRequest -> IOSer . io_Length    = Length;
  1328.  
  1329.                         if(!DoIO(ReadRequest))
  1330.                         {
  1331.                             BytesIn += Length;
  1332.  
  1333.                                 /* Send the data to the console. */
  1334.  
  1335.                             ConProcess(ReadBuffer,Length);
  1336.  
  1337.                             Status = STATUS_READY;
  1338.                         }
  1339.                     }
  1340.                 }
  1341.  
  1342.                 RestartSerial();
  1343.             }
  1344.  
  1345.             if(Signals & SIG_BREAK)
  1346.             {
  1347.                 StopTime();
  1348.  
  1349.                 Results[0] = RC_WARN;
  1350.  
  1351.                 break;
  1352.             }
  1353.  
  1354.             if(Signals & SIG_TIMER)
  1355.             {
  1356.                 WaitIO(TimeRequest);
  1357.  
  1358.                 break;
  1359.             }
  1360.  
  1361.             if(Quiet)
  1362.                 Signals = Wait(SIG_TIMER | SIG_BREAK);
  1363.             else
  1364.                 Signals = Wait(SIG_TIMER | SIG_BREAK | SIG_SERIAL);
  1365.         }
  1366.  
  1367.         DrawCursor();
  1368.  
  1369.         ReleaseWindows();
  1370.     }
  1371.  
  1372.     return(NULL);
  1373. }
  1374.  
  1375. STRPTR __regargs
  1376. RexxDuplex(struct RexxPkt *Pkt)
  1377. {
  1378.     enum    {    ARG_DUPLEX_FULL,ARG_DUPLEX_HALF };
  1379.  
  1380.     BYTE Mode;
  1381.  
  1382.     if(Args[ARG_DUPLEX_FULL])
  1383.         Mode = DUPLEX_FULL;
  1384.  
  1385.     if(Args[ARG_DUPLEX_HALF])
  1386.         Mode = DUPLEX_HALF;
  1387.  
  1388.     if(Config -> SerialConfig -> Duplex != Mode)
  1389.     {
  1390.         Config -> SerialConfig -> Duplex = Mode;
  1391.  
  1392.         UpdateRequired = TRUE;
  1393.  
  1394.         ConfigChanged = TRUE;
  1395.     }
  1396.  
  1397.     return(NULL);
  1398. }
  1399.  
  1400. STRPTR __regargs
  1401. RexxFault(struct RexxPkt *Pkt)
  1402. {
  1403.     enum    {    ARG_FAULT_CODE };
  1404.  
  1405.     LONG    Code = *(LONG *)Args[ARG_FAULT_CODE];
  1406.     UBYTE    RexxResultString[256];
  1407.     STRPTR    Result;
  1408.  
  1409.     if(Code >= ERR10_001 && Code <= ERR10_048)
  1410.         Result = LocaleString(MSG_AREXX_SYSERR10_001_TXT + Code - ERR10_001);
  1411.     else
  1412.     {
  1413.         if(Code >= TERMERROR_NO_DATA_TO_PROCESS && Code <= TERMERROR_WRONG_LIST)
  1414.             Result = LocaleString(MSG_AREXX_HOSTERR_000_TXT + Code - TERMERROR_NO_DATA_TO_PROCESS);
  1415.         else
  1416.         {
  1417.             Fault(Code,"",RexxResultString,256);
  1418.  
  1419.             Result = &RexxResultString[2];
  1420.         }
  1421.     }
  1422.  
  1423.     return(CreateResult(Result,Results));
  1424. }
  1425.  
  1426. STRPTR __regargs
  1427. RexxGetClip(struct RexxPkt *Pkt)
  1428. {
  1429.     enum    {    ARG_GETCLIP_UNIT };
  1430.  
  1431.     struct IFFHandle    *Handle;
  1432.     STRPTR             ResultBuffer = NULL;
  1433.  
  1434.     if(Handle = AllocIFF())
  1435.     {
  1436.         if(Args[ARG_GETCLIP_UNIT])
  1437.             Handle -> iff_Stream = (ULONG)OpenClipboard(*(LONG *)Args[ARG_GETCLIP_UNIT]);
  1438.         else
  1439.             Handle -> iff_Stream = (ULONG)OpenClipboard(Config -> ClipConfig -> ClipboardUnit);
  1440.  
  1441.         if(Handle -> iff_Stream)
  1442.         {
  1443.             InitIFFasClip(Handle);
  1444.  
  1445.             if(!OpenIFF(Handle,IFFF_READ))
  1446.             {
  1447.                 if(!StopChunk(Handle,ID_FTXT,ID_CHRS))
  1448.                 {
  1449.                     if(!ParseIFF(Handle,IFFPARSE_SCAN))
  1450.                     {
  1451.                         struct ContextNode *ContextNode;
  1452.  
  1453.                         ContextNode = CurrentChunk(Handle);
  1454.  
  1455.                         if(ContextNode -> cn_Type == ID_FTXT && ContextNode -> cn_Size > 0)
  1456.                         {
  1457.                             STRPTR Result;
  1458.  
  1459.                             if(Result = (STRPTR)AllocVec(ContextNode -> cn_Size,MEMF_ANY))
  1460.                             {
  1461.                                 if(ReadChunkBytes(Handle,Result,ContextNode -> cn_Size) == ContextNode -> cn_Size)
  1462.                                     ResultBuffer = CreateArgstring(Result,ContextNode -> cn_Size);
  1463.  
  1464.                                 FreeVec(Result);
  1465.                             }
  1466.                             else
  1467.                             {
  1468.                                 Results[0] = RC_ERROR;
  1469.                                 Results[1] = ERROR_NO_FREE_STORE;
  1470.                             }
  1471.                         }
  1472.                         else
  1473.                             Results[0] = RC_WARN;
  1474.                     }
  1475.                     else
  1476.                     {
  1477.                         Results[0] = RC_ERROR;
  1478.                         Results[1] = ERROR_OBJECT_NOT_FOUND;
  1479.                     }
  1480.                 }
  1481.                 else
  1482.                 {
  1483.                     Results[0] = RC_ERROR;
  1484.                     Results[1] = ERROR_OBJECT_NOT_FOUND;
  1485.                 }
  1486.  
  1487.                 CloseIFF(Handle);
  1488.             }
  1489.             else
  1490.             {
  1491.                 Results[0] = RC_ERROR;
  1492.                 Results[1] = ERROR_OBJECT_NOT_FOUND;
  1493.             }
  1494.  
  1495.             CloseClipboard((struct ClipboardHandle *)Handle -> iff_Stream);
  1496.         }
  1497.         else
  1498.         {
  1499.             Results[0] = RC_ERROR;
  1500.             Results[1] = TERMERROR_UNIT_NOT_AVAILABLE;
  1501.         }
  1502.  
  1503.         FreeIFF(Handle);
  1504.     }
  1505.     else
  1506.     {
  1507.         Results[0] = RC_ERROR;
  1508.         Results[1] = ERROR_OBJECT_NOT_FOUND;
  1509.     }
  1510.  
  1511.     return(ResultBuffer);
  1512. }
  1513.  
  1514. STRPTR __regargs
  1515. RexxHangup(struct RexxPkt *Pkt)
  1516. {
  1517.     BYTE OldStatus = Status;
  1518.  
  1519.     if(!WriteRequest)
  1520.     {
  1521.         Results[0] = RC_WARN;
  1522.  
  1523.         return(NULL);
  1524.     }
  1525.  
  1526.     BlockWindows();
  1527.  
  1528.     Status = STATUS_HANGUP;
  1529.  
  1530.         /* Are we to drop the DTR line
  1531.          * before sending the hangup
  1532.          * string?
  1533.          */
  1534.  
  1535.     if(Config -> ModemConfig -> DropDTR)
  1536.     {
  1537.             /* Let's be nice and try to transmit the
  1538.              * `drop the line' command before
  1539.              * trying to close and reopen the driver.
  1540.              */
  1541.  
  1542.         WriteRequest -> IOSer . io_Command    = SIOCMD_SETCTRLLINES;
  1543.         WriteRequest -> IOSer . io_Offset    = SIOB_DTRF;
  1544.         WriteRequest -> IOSer . io_Length    = 0;
  1545.  
  1546.             /* Transmit the command. */
  1547.  
  1548.         if(!DoIO(WriteRequest))
  1549.         {
  1550.                 /* Wait a bit... */
  1551.  
  1552.             WaitTime(1,0);
  1553.  
  1554.                 /* Raise the line again. */
  1555.  
  1556.             WriteRequest -> IOSer . io_Command    = SIOCMD_SETCTRLLINES;
  1557.             WriteRequest -> IOSer . io_Offset    = SIOB_DTRF;
  1558.             WriteRequest -> IOSer . io_Length    = SIOB_DTRF;
  1559.  
  1560.             DoIO(WriteRequest);
  1561.         }
  1562.         else
  1563.         {
  1564.                 /* Do it the standard way: close and reopen
  1565.                  * the serial driver (the serial.device is
  1566.                  * supposed to drop the DTR line when closed).
  1567.                  */
  1568.  
  1569.             if(!DropDTR())
  1570.             {
  1571.                 if(!MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_FAILED_TO_REOPEN_UNIT_TXT),LocaleString(MSG_TERMMAIN_IGNORE_QUIT_TXT),Config -> SerialConfig -> SerialDevice,Config -> SerialConfig -> UnitNumber))
  1572.                     MainTerminated = TRUE;
  1573.             }
  1574.         }
  1575.     }
  1576.  
  1577.         /* Transmit the hangup command. */
  1578.  
  1579.     LocalRexxSerialCommand(Config -> ModemConfig -> ModemHangup,NULL);
  1580.  
  1581.         /* Reset to old status. */
  1582.  
  1583.     Status = OldStatus;
  1584.  
  1585.         /* We are no longer online. */
  1586.  
  1587.     Online = FALSE;
  1588.  
  1589.         /* Reset time limit. */
  1590.  
  1591.     LimitCount = -1;
  1592.  
  1593.         /* Clear the password. */
  1594.  
  1595.     Password[0]        = 0;
  1596.     UserName[0]        = 0;
  1597.  
  1598.     CurrentBBSName[0]    = 0;
  1599.     CurrentBBSComment[0]    = 0;
  1600.     CurrentBBSNumber[0]    = 0;
  1601.  
  1602.         /* Note the  last action. */
  1603.  
  1604.     LogAction(LocaleString(MSG_TERMMAIN_LOGMSG_HANG_UP_TXT));
  1605.  
  1606.     ReleaseWindows();
  1607.  
  1608.         /* Execute logoff macro. */
  1609.  
  1610.     if(WasOnline)
  1611.         LocalRexxSerialCommand(Config -> CommandConfig -> LogoffMacro,NULL);
  1612.  
  1613.         /* Update the logfile. */
  1614.  
  1615.     StopCall(FALSE);
  1616.  
  1617.         /* Don't execute the logoff macro twice. */
  1618.  
  1619.     WasOnline = FALSE;
  1620.  
  1621.         /* Enable the dialing functions. */
  1622.  
  1623.     SetDialMenu(TRUE);
  1624.  
  1625.     Status = OldStatus;
  1626.  
  1627.     if(Config -> ModemConfig -> RedialAfterHangup)
  1628.     {
  1629.         if(DialList)
  1630.         {
  1631.             if(DialList -> lh_Head -> ln_Succ)
  1632.                 DoDial = DIAL_REDIAL;
  1633.         }
  1634.     }
  1635.  
  1636.     ChosenEntry = NULL;
  1637.  
  1638.     return(NULL);
  1639. }
  1640.  
  1641. STRPTR __regargs
  1642. RexxHelp(struct RexxPkt *Pkt)
  1643. {
  1644.     enum    {    ARG_HELP_COMMAND,ARG_HELP_PROMPT };
  1645.  
  1646.     if(Args[ARG_HELP_PROMPT])
  1647.         GuideSetup();
  1648.     else
  1649.     {
  1650.         WORD i;
  1651.  
  1652.         for(i = 0 ; i < CommandTableSize ; i++)
  1653.         {
  1654.             if(!Stricmp(Args[ARG_HELP_COMMAND],CommandTable[i] . Name))
  1655.             {
  1656.                 if(CommandTable[i] . Arguments)
  1657.                     return(CreateResult(CommandTable[i] . Arguments,Results));
  1658.                 else
  1659.                     return(CreateResult(",",Results));
  1660.             }
  1661.         }
  1662.  
  1663.         Results[0] = RC_ERROR;
  1664.         Results[1] = ERROR_OBJECT_NOT_FOUND;
  1665.     }
  1666.  
  1667.     return(NULL);
  1668. }
  1669.  
  1670. STRPTR __regargs
  1671. RexxOpen(struct RexxPkt *Pkt)
  1672. {
  1673.     enum    {    ARG_OPEN_NAME,ARG_OPEN_TO };
  1674.  
  1675.     WORD Index = ToConfig(Args[ARG_OPEN_TO]);
  1676.  
  1677.     if(Index == -1 || Index > DATATYPE_PHONEBOOK)
  1678.     {
  1679.         Results[0] = RC_ERROR;
  1680.         Results[1] = ERROR_OBJECT_NOT_FOUND;
  1681.     }
  1682.     else
  1683.     {
  1684.         UBYTE    DummyBuffer[MAX_FILENAME_LENGTH];
  1685.         STRPTR    FileName;
  1686.  
  1687.         if(Args[ARG_OPEN_NAME])
  1688.             FileName = Args[ARG_OPEN_NAME];
  1689.         else
  1690.         {
  1691.             STRPTR             Title;
  1692.             struct FileRequester    *FileRequest;
  1693.  
  1694.             FileName = NULL;
  1695.  
  1696.             switch(Index)
  1697.             {
  1698.                 case DATATYPE_TRANSLATIONS:
  1699.  
  1700.                     Title = LocaleString(MSG_PHONEPANEL_SELECT_TRANSLATION_TXT);
  1701.                     break;
  1702.  
  1703.                 case DATATYPE_FUNCTIONKEYS:
  1704.  
  1705.                     Title = LocaleString(MSG_PHONEPANEL_SELECT_KEYBOARD_MACROS_TXT);
  1706.                     break;
  1707.  
  1708.                 case DATATYPE_CURSORKEYS:
  1709.  
  1710.                     Title = LocaleString(MSG_PHONEPANEL_SELECT_CURSOR_KEYS_TXT);
  1711.                     break;
  1712.  
  1713.                 case DATATYPE_FASTMACROS:
  1714.  
  1715.                     Title = LocaleString(MSG_PHONEPANEL_SELECT_FAST_MACROS_TXT);
  1716.                     break;
  1717.  
  1718.                 case DATATYPE_HOTKEYS:
  1719.  
  1720.                     Title = LocaleString(MSG_HOTKEYPANEL_LOAD_HOTKEYS_TXT);
  1721.                     break;
  1722.  
  1723.                 case DATATYPE_SPEECH:
  1724.  
  1725.                     Title = LocaleString(MSG_SPEECHPANEL_LOAD_SPEECH_SETTINGS_TXT);
  1726.                     break;
  1727.  
  1728.                 case DATATYPE_SOUND:
  1729.  
  1730.                     Title = LocaleString(MSG_SOUNDPANEL_LOAD_SOUNDS_TXT);
  1731.                     break;
  1732.  
  1733.                 case DATATYPE_BUFFER:
  1734.  
  1735.                     Title = LocaleString(MSG_TERMMAIN_LOAD_BUFFER_TXT);
  1736.                     break;
  1737.  
  1738.                 case DATATYPE_CONFIGURATION:
  1739.  
  1740.                     Title = LocaleString(MSG_TERMMAIN_OPEN_PREFERENCES_TXT);
  1741.                     break;
  1742.  
  1743.                 case DATATYPE_PHONEBOOK:
  1744.  
  1745.                     Title = LocaleString(MSG_PHONEPANEL_LOAD_PHONEBOOK_TXT);
  1746.                     break;
  1747.             }
  1748.  
  1749.             BlockWindows();
  1750.  
  1751.             if(FileRequest = GetFile(Title,"","",DummyBuffer,NULL,FALSE,FALSE,FALSE,"Ok",TRUE))
  1752.             {
  1753.                 FileName = DummyBuffer;
  1754.  
  1755.                 FreeAslRequest(FileRequest);
  1756.             }
  1757.             else
  1758.                 Results[0] = RC_WARN;
  1759.  
  1760.             ReleaseWindows();
  1761.         }
  1762.  
  1763.         if(FileName)
  1764.         {
  1765.             if(!GetFileSize(FileName))
  1766.             {
  1767.                 Results[0] = RC_ERROR;
  1768.                 Results[1] = ERROR_OBJECT_NOT_FOUND;
  1769.  
  1770.                 return(NULL);
  1771.             }
  1772.  
  1773.             BlockWindows();
  1774.  
  1775.             switch(Index)
  1776.             {
  1777.                 case DATATYPE_TRANSLATIONS:
  1778.                 {
  1779.                     struct TranslationEntry    **Send,
  1780.                                 **Receive = NULL;
  1781.                     BYTE            Success = FALSE;
  1782.  
  1783.                     if(Send = AllocTranslationTable())
  1784.                     {
  1785.                         if(Receive = AllocTranslationTable())
  1786.                         {
  1787.                             if(!(Success = LoadTranslationTables(FileName,Send,Receive)))
  1788.                             {
  1789.                                 Results[0] = RC_ERROR;
  1790.                                 Results[1] = IoErr();
  1791.                             }
  1792.                         }
  1793.                         else
  1794.                         {
  1795.                             Results[0] = RC_ERROR;
  1796.                             Results[1] = ERROR_NO_FREE_STORE;
  1797.                         }
  1798.                     }
  1799.                     else
  1800.                     {
  1801.                         Results[0] = RC_ERROR;
  1802.                         Results[1] = ERROR_NO_FREE_STORE;
  1803.                     }
  1804.  
  1805.                     if(!Success)
  1806.                     {
  1807.                         if(Send)
  1808.                             FreeTranslationTable(Send);
  1809.  
  1810.                         if(Receive)
  1811.                             FreeTranslationTable(Receive);
  1812.                     }
  1813.                     else
  1814.                     {
  1815.                         strcpy(Config -> FileConfig -> TranslationFileName,FileName);
  1816.  
  1817.                         strcpy(LastTranslation,FileName);
  1818.  
  1819.                         FreeTranslationTable(SendTable);
  1820.                         FreeTranslationTable(ReceiveTable);
  1821.  
  1822.                         SendTable    = Send;
  1823.                         ReceiveTable    = Receive;
  1824.                     }
  1825.                 }
  1826.  
  1827.                 break;
  1828.  
  1829.                 case DATATYPE_FUNCTIONKEYS:
  1830.                 {
  1831.                     if(!LoadMacros(FileName,MacroKeys))
  1832.                     {
  1833.                         Results[0] = RC_ERROR;
  1834.                         Results[1] = IoErr();
  1835.                     }
  1836.                     else
  1837.                     {
  1838.                         MacroChanged = FALSE;
  1839.  
  1840.                         strcpy(Config -> FileConfig -> MacroFileName,FileName);
  1841.  
  1842.                         strcpy(LastMacros,FileName);
  1843.                     }
  1844.                 }
  1845.  
  1846.                 break;
  1847.  
  1848.                 case DATATYPE_CURSORKEYS:
  1849.                 {
  1850.                     if(!ReadIFFData(FileName,CursorKeys,sizeof(struct CursorKeys),ID_KEYS))
  1851.                     {
  1852.                         Results[0] = RC_ERROR;
  1853.                         Results[1] = IoErr();
  1854.                     }
  1855.                     else
  1856.                     {
  1857.                         CursorKeysChanged = FALSE;
  1858.  
  1859.                         strcpy(Config -> FileConfig -> CursorFileName,FileName);
  1860.  
  1861.                         strcpy(LastCursorKeys,FileName);
  1862.                     }
  1863.                 }
  1864.  
  1865.                 break;
  1866.  
  1867.                 case DATATYPE_FASTMACROS:
  1868.                 {
  1869.                     if(!LoadFastMacros(FileName))
  1870.                     {
  1871.                         Results[0] = RC_ERROR;
  1872.                         Results[1] = IoErr();
  1873.                     }
  1874.                     else
  1875.                     {
  1876.                         strcpy(Config -> FileConfig -> FastMacroFileName,FileName);
  1877.  
  1878.                         strcpy(LastFastMacros,FileName);
  1879.  
  1880.                         FastMacrosChanged = FALSE;
  1881.                     }
  1882.  
  1883.                     RefreshFastWindow(TRUE);
  1884.                 }
  1885.  
  1886.                 break;
  1887.  
  1888.                 case DATATYPE_HOTKEYS:
  1889.                 {
  1890.                     if(!LoadHotkeys(FileName,&Hotkeys))
  1891.                     {
  1892.                         Results[0] = RC_ERROR;
  1893.                         Results[1] = IoErr();
  1894.                     }
  1895.                     else
  1896.                     {
  1897.                         strcpy(LastKeys,FileName);
  1898.  
  1899.                         HotkeysChanged = FALSE;
  1900.  
  1901.                         SetupCx();
  1902.                     }
  1903.                 }
  1904.  
  1905.                 break;
  1906.  
  1907.                 case DATATYPE_SPEECH:
  1908.                 {
  1909.                     if(!ReadIFFData(FileName,&SpeechConfig,sizeof(struct SpeechConfig),ID_SPEK))
  1910.                     {
  1911.                         Results[0] = RC_ERROR;
  1912.                         Results[1] = IoErr();
  1913.                     }
  1914.                     else
  1915.                     {
  1916.                         strcpy(LastSpeech,FileName);
  1917.  
  1918.                         SpeechSetup();
  1919.  
  1920.                         SpeechChanged = FALSE;
  1921.                     }
  1922.                 }
  1923.  
  1924.                 break;
  1925.  
  1926.                 case DATATYPE_SOUND:
  1927.                 {
  1928.                     if(!ReadIFFData(FileName,&SoundConfig,sizeof(struct SoundConfig),ID_SOUN))
  1929.                     {
  1930.                         Results[0] = RC_ERROR;
  1931.                         Results[1] = IoErr();
  1932.                     }
  1933.                     else
  1934.                     {
  1935.                         strcpy(LastSound,FileName);
  1936.  
  1937.                         SoundInit();
  1938.  
  1939.                         SoundChanged = FALSE;
  1940.                     }
  1941.                 }
  1942.  
  1943.                 break;
  1944.  
  1945.                 case DATATYPE_BUFFER:
  1946.                 {
  1947.                     BPTR SomeFile;
  1948.  
  1949.                     if(SomeFile = Open(FileName,MODE_OLDFILE))
  1950.                     {
  1951.                         LONG Len;
  1952.  
  1953.                         LineRead(NULL,NULL,NULL);
  1954.  
  1955.                         while((Len = LineRead(SomeFile,FileName,80)) > 0)
  1956.                             StoreBuffer(FileName,Len);
  1957.  
  1958.                         Close(SomeFile);
  1959.  
  1960.                         BufferChanged = TRUE;
  1961.                     }
  1962.                     else
  1963.                     {
  1964.                         Results[0] = RC_ERROR;
  1965.                         Results[1] = IoErr();
  1966.                     }
  1967.                 }
  1968.  
  1969.                 break;
  1970.  
  1971.                 case DATATYPE_CONFIGURATION:
  1972.                 {
  1973.                     if(ReadConfig(FileName,PrivateConfig))
  1974.                     {
  1975.                         SwapConfig(PrivateConfig,Config);
  1976.  
  1977.                         strcpy(FileName,LastConfig);
  1978.  
  1979.                         ConfigSetup();
  1980.  
  1981.                         ConfigChanged = FALSE;
  1982.                     }
  1983.                     else
  1984.                     {
  1985.                         Results[0] = RC_ERROR;
  1986.                         Results[1] = IoErr();
  1987.                     }
  1988.                 }
  1989.  
  1990.                 break;
  1991.  
  1992.                 case DATATYPE_PHONEBOOK:
  1993.                 {
  1994.                     if(ChosenEntry)
  1995.                     {
  1996.                         Results[0] = RC_ERROR;
  1997.                         Results[1] = ERROR_OBJECT_IN_USE;
  1998.                     }
  1999.                     else
  2000.                     {
  2001.                         if(!LoadPhonebook(FileName))
  2002.                         {
  2003.                             Results[0] = RC_ERROR;
  2004.                             Results[1] = IoErr();
  2005.                         }
  2006.                         else
  2007.                         {
  2008.                             strcpy(LastPhone,FileName);
  2009.  
  2010.                             PhonebookChanged = FALSE;
  2011.  
  2012.                             RebuildMenu = TRUE;
  2013.                         }
  2014.                     }
  2015.                 }
  2016.  
  2017.                 break;
  2018.             }
  2019.  
  2020.             ReleaseWindows();
  2021.         }
  2022.         else
  2023.             Results[0] = RC_WARN;
  2024.     }
  2025.  
  2026.     return(NULL);
  2027. }
  2028.  
  2029. STRPTR __regargs
  2030. RexxOpenDevice(struct RexxPkt *Pkt)
  2031. {
  2032.     enum    {    ARG_OPENDEVICE_NAME,ARG_OPENDEVICE_UNIT };
  2033.  
  2034.     if(ReadRequest)
  2035.     {
  2036.         Results[0] = RC_ERROR;
  2037.         Results[1] = TERMERROR_DEVICE_DRIVER_STILL_OPEN;
  2038.     }
  2039.     else
  2040.     {
  2041.         if(Args[ARG_OPENDEVICE_NAME])
  2042.         {
  2043.             strcpy(Config -> SerialConfig -> SerialDevice,Args[ARG_OPENDEVICE_NAME]);
  2044.  
  2045.             ConfigChanged = TRUE;
  2046.         }
  2047.  
  2048.         if(Args[ARG_OPENDEVICE_UNIT])
  2049.         {
  2050.             Config -> SerialConfig -> UnitNumber = *(LONG *)Args[ARG_OPENDEVICE_UNIT];
  2051.  
  2052.             ConfigChanged = TRUE;
  2053.         }
  2054.  
  2055.         BlockWindows();
  2056.  
  2057.         ReopenSerial();
  2058.  
  2059.         ReleaseWindows();
  2060.     }
  2061.  
  2062.     return(NULL);
  2063. }
  2064.  
  2065. STRPTR __regargs
  2066. RexxOpenRequester(struct RexxPkt *Pkt)
  2067. {
  2068.     enum    {    ARG_OPENREQUESTER_REQUESTER };
  2069.  
  2070.     WORD Index;
  2071.  
  2072.     if((Index = ToRequester(Args[ARG_OPENREQUESTER_REQUESTER])) == -1)
  2073.     {
  2074.         Results[0] = RC_ERROR;
  2075.         Results[1] = ERROR_OBJECT_NOT_FOUND;
  2076.     }
  2077.     else
  2078.     {
  2079.         ULONG    Code;
  2080.         WORD    i;
  2081.  
  2082.         switch(Index)
  2083.         {
  2084.             case REQUESTER_SERIAL:
  2085.  
  2086.                 Code = MEN_SERIAL;
  2087.                 break;
  2088.  
  2089.             case REQUESTER_MODEM:
  2090.  
  2091.                 Code = MEN_MODEM;
  2092.                 break;
  2093.  
  2094.             case REQUESTER_SCREEN:
  2095.  
  2096.                 Code = MEN_SCREEN;
  2097.                 break;
  2098.  
  2099.             case REQUESTER_TERMINAL:
  2100.  
  2101.                 Code = MEN_TERMINAL;
  2102.                 break;
  2103.  
  2104.             case REQUESTER_EMULATION:
  2105.  
  2106.                 Code = MEN_SET_EMULATION;
  2107.                 break;
  2108.  
  2109.             case REQUESTER_CLIPBOARD:
  2110.  
  2111.                 Code = MEN_CLIPBOARD;
  2112.                 break;
  2113.  
  2114.             case REQUESTER_CAPTURE:
  2115.  
  2116.                 Code = MEN_CAPTURE;
  2117.                 break;
  2118.  
  2119.             case REQUESTER_COMMANDS:
  2120.  
  2121.                 Code = MEN_COMMANDS;
  2122.                 break;
  2123.  
  2124.             case REQUESTER_MISC:
  2125.  
  2126.                 Code = MEN_MISC;
  2127.                 break;
  2128.  
  2129.             case REQUESTER_PATH:
  2130.  
  2131.                 Code = MEN_PATH;
  2132.                 break;
  2133.  
  2134.             case REQUESTER_TRANSFER:
  2135.  
  2136.                 Code = MEN_TRANSFER;
  2137.                 break;
  2138.  
  2139.             case REQUESTER_TRANSLATIONS:
  2140.  
  2141.                 Code = MEN_TRANSLATION;
  2142.                 break;
  2143.  
  2144.             case REQUESTER_FUNCTIONKEYS:
  2145.  
  2146.                 Code = MEN_MACROS;
  2147.                 break;
  2148.  
  2149.             case REQUESTER_CURSORKEYS:
  2150.  
  2151.                 Code = MEN_CURSORKEYS;
  2152.                 break;
  2153.  
  2154.             case REQUESTER_FASTMACROS:
  2155.  
  2156.                 Code = MEN_FAST_MACROS;
  2157.                 break;
  2158.  
  2159.             case REQUESTER_HOTKEYS:
  2160.  
  2161.                 Code = MEN_HOTKEYS;
  2162.                 break;
  2163.  
  2164.             case REQUESTER_SPEECH:
  2165.  
  2166.                 Code = MEN_SPEECH;
  2167.                 break;
  2168.  
  2169.             case REQUESTER_SOUND:
  2170.  
  2171.                 Code = MEN_SOUND;
  2172.                 break;
  2173.  
  2174.  
  2175.             case REQUESTER_PHONE:
  2176.  
  2177.                 Code = MEN_PHONEBOOK;
  2178.                 break;
  2179.         }
  2180.  
  2181.             /* Scan the menu list... */
  2182.  
  2183.         for(i = 0 ; TermMenu[i] . nm_Type != NM_END ; i++)
  2184.         {
  2185.                 /* Did we get a valid name string? */
  2186.  
  2187.             if(TermMenu[i] . nm_Label != NM_BARLABEL)
  2188.             {
  2189.                 if((ULONG)TermMenu[i] . nm_UserData == Code)
  2190.                 {
  2191.                     HandleMenuCode((ULONG)TermMenu[i] . nm_UserData,NULL);
  2192.  
  2193.                     break;
  2194.                 }
  2195.             }
  2196.         }
  2197.     }
  2198.  
  2199.     return(NULL);
  2200. }
  2201.  
  2202. STRPTR __regargs
  2203. RexxParity(struct RexxPkt *Pkt)
  2204. {
  2205.     enum    {    ARG_PARITY_EVEN,ARG_PARITY_ODD,ARG_PARITY_NONE,ARG_PARITY_MARK,ARG_PARITY_SPACE };
  2206.  
  2207.     BYTE Mode;
  2208.  
  2209.     if(Args[ARG_PARITY_EVEN])
  2210.         Mode = PARITY_EVEN;
  2211.  
  2212.     if(Args[ARG_PARITY_ODD])
  2213.         Mode = PARITY_ODD;
  2214.  
  2215.     if(Args[ARG_PARITY_NONE])
  2216.         Mode = PARITY_NONE;
  2217.  
  2218.     if(Args[ARG_PARITY_MARK])
  2219.         Mode = PARITY_MARK;
  2220.  
  2221.     if(Args[ARG_PARITY_SPACE])
  2222.         Mode = PARITY_SPACE;
  2223.  
  2224.     if(Config -> SerialConfig -> Parity != Mode)
  2225.     {
  2226.         Config -> SerialConfig -> Parity = Mode;
  2227.  
  2228.         UpdateRequired = TRUE;
  2229.  
  2230.         ConfigChanged = TRUE;
  2231.     }
  2232.  
  2233.     return(NULL);
  2234. }
  2235.  
  2236. STRPTR __regargs
  2237. RexxPasteClip(struct RexxPkt *Pkt)
  2238. {
  2239.     enum    {    ARG_PASTECLIP_UNIT };
  2240.  
  2241.     LONG Unit;
  2242.  
  2243.     if(Args[ARG_PASTECLIP_UNIT])
  2244.         Unit = *(LONG *)Args[ARG_PASTECLIP_UNIT];
  2245.     else
  2246.         Unit = Config -> ClipConfig -> ClipboardUnit;
  2247.  
  2248.     if(!OpenClip(Unit))
  2249.         ClipInput = TRUE;
  2250.     else
  2251.         ClipInput = FALSE;
  2252.  
  2253.     return(NULL);
  2254. }
  2255.  
  2256. STRPTR __regargs
  2257. RexxPrint(struct RexxPkt *Pkt)
  2258. {
  2259.     enum    {    ARG_PRINT_FROM,ARG_PRINT_TO,ARG_PRINT_SERIAL,ARG_PRINT_MODEM,ARG_PRINT_SCREEN,
  2260.             ARG_PRINT_TERMINAL,ARG_PRINT_USER,ARG_PRINT_COMMENT,ARG_PRINT_SIZE,
  2261.             ARG_PRINT_DATE,ARG_PRINT_BITS };
  2262.  
  2263.     WORD    Index,Mode = -1;
  2264.     ULONG    Flags = NULL;
  2265.  
  2266.     if(Args[ARG_PRINT_SERIAL])
  2267.         Flags |= PRINT_SERIAL;
  2268.  
  2269.     if(Args[ARG_PRINT_MODEM])
  2270.         Flags |= PRINT_MODEM;
  2271.  
  2272.     if(Args[ARG_PRINT_SCREEN])
  2273.         Flags |= PRINT_SCREEN;
  2274.  
  2275.     if(Args[ARG_PRINT_TERMINAL])
  2276.         Flags |= PRINT_TERMINAL;
  2277.  
  2278.     if(Args[ARG_PRINT_USER])
  2279.         Flags |= PRINT_USERNAME;
  2280.  
  2281.     if(Args[ARG_PRINT_COMMENT])
  2282.         Flags |= PRINT_COMMENT;
  2283.  
  2284.     if(Args[ARG_PRINT_SIZE])
  2285.         Flags |= PRINT_SIZE;
  2286.  
  2287.     if(Args[ARG_PRINT_DATE])
  2288.         Flags |= PRINT_DATE;
  2289.  
  2290.     if(Args[ARG_PRINT_BITS])
  2291.         Flags |= PRINT_BITS;
  2292.  
  2293.     if((Index = ToList(Args[ARG_PRINT_FROM])) == -1)
  2294.     {
  2295.         if(!Stricmp(Args[ARG_PRINT_FROM],"SCREENTEXT"))
  2296.         {
  2297.             if(!RasterEnabled)
  2298.             {
  2299.                 Results[0] = RC_ERROR;
  2300.                 Results[1] = TERMERROR_NO_DATA_TO_PROCESS;
  2301.  
  2302.                 return(NULL);
  2303.             }
  2304.             else
  2305.                 Mode = 0;
  2306.         }
  2307.  
  2308.         if(!Stricmp(Args[ARG_PRINT_FROM],"CLIPBOARD"))
  2309.             Mode = 1;
  2310.  
  2311.         if(!Stricmp(Args[ARG_PRINT_FROM],"BUFFER"))
  2312.             Mode = 2;
  2313.     }
  2314.  
  2315.     if(Index == -1 && Mode == -1)
  2316.     {
  2317.         Results[0] = RC_ERROR;
  2318.         Results[1] = TERMERROR_UNKNOWN_LIST;
  2319.     }
  2320.     else
  2321.     {
  2322.         BYTE    Continue = TRUE;
  2323.         LONG    Error = 0;
  2324.         BPTR    File;
  2325.         STRPTR    Name;
  2326.  
  2327.         if(Args[ARG_PRINT_TO])
  2328.             Name = Args[ARG_PRINT_TO];
  2329.         else
  2330.             Name = "PRT:";
  2331.  
  2332.         if(File = Open(Name,MODE_NEWFILE))
  2333.         {
  2334.             struct Window        *ReqWindow;
  2335.             struct EasyStruct     Easy;
  2336.  
  2337.             Easy . es_StructSize    = sizeof(struct EasyStruct);
  2338.             Easy . es_Flags        = NULL;
  2339.             Easy . es_Title        = (UBYTE *)LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  2340.             Easy . es_GadgetFormat    = (UBYTE *)LocaleString(MSG_PRINT_STOP_TXT);
  2341.             Easy . es_TextFormat    = (UBYTE *)LocaleString(MSG_GLOBAL_PRINTING_TXT);
  2342.  
  2343.             BlockWindows();
  2344.  
  2345.             if(ReqWindow = BuildEasyRequest(Window,&Easy,NULL))
  2346.             {
  2347.                 switch(Index)
  2348.                 {
  2349.                     case GLIST_DIAL:
  2350.                     {
  2351.                         struct GenericList *List = GenericListTable[Index];
  2352.  
  2353.                         ObtainSemaphore(&List -> ListSemaphore);
  2354.  
  2355.                         if(List -> ListHeader . mlh_Head -> mln_Succ)
  2356.                         {
  2357.                             struct DialNode *TempNode;
  2358.  
  2359.                             for(TempNode = (struct DialNode *)List -> ListHeader . mlh_Head ; Continue && TempNode -> Node . ln_Succ ; TempNode = (struct DialNode *)TempNode -> Node . ln_Succ)
  2360.                             {
  2361.                                 if(TempNode -> Entry)
  2362.                                     Continue = PrintEntry(File,ReqWindow,TRUE,&Error,TempNode -> Entry,Flags);
  2363.                                 else
  2364.                                     Continue = PrintText(File,ReqWindow,&Error,"\n\"???\" (%s)",TempNode -> Node . ln_Name);
  2365.                             }
  2366.                         }
  2367.  
  2368.                         ReleaseSemaphore(&List -> ListSemaphore);
  2369.                     }
  2370.  
  2371.                     break;
  2372.  
  2373.                     case GLIST_UPLOAD:
  2374.                     case GLIST_DOWNLOAD:
  2375.                     {
  2376.                         struct GenericList *List = GenericListTable[Index];
  2377.  
  2378.                         ObtainSemaphore(&List -> ListSemaphore);
  2379.  
  2380.                         if(List -> ListHeader . mlh_Head -> mln_Succ)
  2381.                         {
  2382.                             struct Node *TempNode;
  2383.  
  2384.                             for(TempNode = (struct Node *)List -> ListHeader . mlh_Head ; Continue && TempNode -> ln_Succ ; TempNode = TempNode -> ln_Succ)
  2385.                                 Continue = PrintFileInformation(File,ReqWindow,&Error,TempNode -> ln_Name,Flags);
  2386.                         }
  2387.  
  2388.                         ReleaseSemaphore(&List -> ListSemaphore);
  2389.                     }
  2390.  
  2391.                     break;
  2392.  
  2393.                     case GLIST_WAIT:
  2394.                     {
  2395.                         struct GenericList *List = GenericListTable[Index];
  2396.  
  2397.                         ObtainSemaphore(&List -> ListSemaphore);
  2398.  
  2399.                         if(List -> ListHeader . mlh_Head -> mln_Succ)
  2400.                         {
  2401.                             struct Node *TempNode;
  2402.  
  2403.                             for(TempNode = (struct Node *)List -> ListHeader . mlh_Head ; Continue && TempNode -> ln_Succ ; TempNode = TempNode -> ln_Succ)
  2404.                                 Continue = PrintText(File,ReqWindow,&Error,"%s\n",TempNode -> ln_Name);
  2405.                         }
  2406.  
  2407.                         ReleaseSemaphore(&List -> ListSemaphore);
  2408.                     }
  2409.  
  2410.                     break;
  2411.  
  2412.                     default:
  2413.                     {
  2414.                         switch(Mode)
  2415.                         {
  2416.                             case 0:
  2417.  
  2418.                                 Continue = PrintScreen(File,ReqWindow,&Error);
  2419.                                 break;
  2420.  
  2421.                             case 1:
  2422.  
  2423.                                 Continue = PrintClip(File,ReqWindow,&Error);
  2424.                                 break;
  2425.  
  2426.                             case 2:
  2427.  
  2428.                                 Continue = PrintBuffer(File,ReqWindow,&Error);
  2429.                                 break;
  2430.                         }
  2431.  
  2432.                         break;
  2433.                     }
  2434.  
  2435.                     break;
  2436.                 }
  2437.  
  2438.                 FreeSysRequest(ReqWindow);
  2439.             }
  2440.  
  2441.             ReleaseWindows();
  2442.  
  2443.             Close(File);
  2444.         }
  2445.         else
  2446.             Error = IoErr();
  2447.  
  2448.         if(Error)
  2449.         {
  2450.             Results[0] = RC_ERROR;
  2451.             Results[1] = Error;
  2452.         }
  2453.         else
  2454.         {
  2455.             if(!Continue)
  2456.                 Results[0] = RC_WARN;
  2457.         }
  2458.     }
  2459.  
  2460.     return(NULL);
  2461. }
  2462.  
  2463. STRPTR __regargs
  2464. RexxProtocol(struct RexxPkt *Pkt)
  2465. {
  2466.     enum    {    ARG_PROTOCOL_NONE,ARG_PROTOCOL_RTSCTS,ARG_PROTOCOL_RTSCTSDTR };
  2467.  
  2468.     BYTE Mode;
  2469.  
  2470.     if(Args[ARG_PROTOCOL_NONE])
  2471.         Mode = HANDSHAKING_NONE;
  2472.  
  2473.     if(Args[ARG_PROTOCOL_RTSCTS])
  2474.         Mode = HANDSHAKING_RTSCTS;
  2475.  
  2476.     if(Args[ARG_PROTOCOL_RTSCTSDTR])
  2477.         Mode = HANDSHAKING_RTSCTS_DSR;
  2478.  
  2479.     if(Config -> SerialConfig -> HandshakingProtocol != Mode)
  2480.     {
  2481.         Config -> SerialConfig -> HandshakingProtocol = Mode;
  2482.  
  2483.         UpdateRequired = TRUE;
  2484.  
  2485.         ConfigChanged = TRUE;
  2486.     }
  2487.  
  2488.     return(NULL);
  2489. }
  2490.  
  2491. STRPTR __regargs
  2492. RexxPutClip(struct RexxPkt *Pkt)
  2493. {
  2494.     enum    {    ARG_PUTCLIP_UNIT,ARG_PUTCLIP_TEXT };
  2495.  
  2496.     struct IFFHandle    *Handle;
  2497.     LONG             Unit;
  2498.     BYTE             Success = FALSE;
  2499.  
  2500.     if(Args[ARG_PUTCLIP_UNIT])
  2501.         Unit = *(LONG *)Args[ARG_PUTCLIP_UNIT];
  2502.     else
  2503.         Unit = Config -> ClipConfig -> ClipboardUnit;
  2504.  
  2505.     if(Handle = AllocIFF())
  2506.     {
  2507.         if(Handle -> iff_Stream = (ULONG)OpenClipboard(Unit))
  2508.         {
  2509.             InitIFFasClip(Handle);
  2510.  
  2511.             if(!OpenIFF(Handle,IFFF_WRITE))
  2512.             {
  2513.                 if(!PushChunk(Handle,ID_FTXT,ID_FORM,IFFSIZE_UNKNOWN))
  2514.                 {
  2515.                     if(!PushChunk(Handle,0,ID_CHRS,IFFSIZE_UNKNOWN))
  2516.                     {
  2517.                         LONG Len = strlen(Args[ARG_PUTCLIP_TEXT]);
  2518.  
  2519.                         if(WriteChunkBytes(Handle,Args[ARG_PUTCLIP_TEXT],Len) == Len)
  2520.                         {
  2521.                             if(!PopChunk(Handle))
  2522.                                 Success = TRUE;
  2523.                         }
  2524.                     }
  2525.                 }
  2526.  
  2527.                 if(PopChunk(Handle))
  2528.                     Success = FALSE;
  2529.  
  2530.                 CloseIFF(Handle);
  2531.             }
  2532.             else
  2533.             {
  2534.                 Results[0] = RC_ERROR;
  2535.                 Results[1] = ERROR_NO_FREE_STORE;
  2536.             }
  2537.  
  2538.             CloseClipboard((struct ClipboardHandle *)Handle -> iff_Stream);
  2539.         }
  2540.         else
  2541.         {
  2542.             Results[0] = RC_ERROR;
  2543.             Results[1] = TERMERROR_UNIT_NOT_AVAILABLE;
  2544.         }
  2545.  
  2546.         FreeIFF(Handle);
  2547.     }
  2548.     else
  2549.     {
  2550.         Results[0] = RC_ERROR;
  2551.         Results[1] = ERROR_NO_FREE_STORE;
  2552.     }
  2553.  
  2554.     if(!Success && !Results[0])
  2555.     {
  2556.         Results[0] = RC_ERROR;
  2557.         Results[1] = TERMERROR_CLIPBOARD_ERROR;
  2558.     }
  2559.  
  2560.     return(NULL);
  2561. }
  2562.  
  2563. STRPTR __regargs
  2564. RexxQuit(struct RexxPkt *Pkt)
  2565. {
  2566.     enum    {    ARG_QUIT_FORCE };
  2567.  
  2568.     if(Args[ARG_QUIT_FORCE])
  2569.         MainTerminated = TRUE;
  2570.     else
  2571.         HandleMenuCode(MEN_QUIT,NULL);
  2572.  
  2573.     return(NULL);
  2574. }
  2575.  
  2576. STRPTR __regargs
  2577. RexxRead(struct RexxPkt *Pkt)
  2578. {
  2579.     enum    {    ARG_READ_NUM,ARG_READ_CR,ARG_READ_NOECHO,ARG_READ_VERBATIM,ARG_READ_PROMPT };
  2580.  
  2581.     LONG Len,BytesRead = 0;
  2582.  
  2583.     if(!ReadRequest || !WriteRequest)
  2584.     {
  2585.         Results[0] = RC_WARN;
  2586.  
  2587.         return(NULL);
  2588.     }
  2589.  
  2590.     if(Args[ARG_READ_NUM])
  2591.     {
  2592.         Len = *(LONG *)Args[ARG_READ_NUM] + 1;
  2593.  
  2594.         if(Len < 1)
  2595.         {
  2596.             Results[0] = RC_ERROR;
  2597.             Results[1] = ERROR_BAD_NUMBER;
  2598.  
  2599.             return(NULL);
  2600.         }
  2601.  
  2602.         if(Len > MAX_RESULT_LEN + 1)
  2603.             Len = MAX_RESULT_LEN + 1;
  2604.     }
  2605.     else
  2606.         Len = MAX_RESULT_LEN + 1;
  2607.  
  2608.     if(Args[ARG_READ_PROMPT])
  2609.         LocalRexxSerialCommand(Args[ARG_READ_PROMPT],NULL);
  2610.  
  2611.     BlockWindows();
  2612.  
  2613.     Status = STATUS_READY;
  2614.  
  2615.     if(Args[ARG_READ_VERBATIM] || !ReceiveTable)
  2616.     {
  2617.         if(Args[ARG_READ_NUM])
  2618.         {
  2619.             STRPTR Buffer;
  2620.  
  2621.             if(Buffer = (STRPTR)AllocVec(Len,MEMF_ANY))
  2622.             {
  2623.                 STRPTR Result;
  2624.  
  2625.                 if(DataHold && DataSize >= Len - 1)
  2626.                 {
  2627.                     CopyMem(DataHold,Buffer,Len - 1);
  2628.  
  2629.                     BytesRead = Len - 1;
  2630.  
  2631.                     if(Len - 1 == DataSize)
  2632.                     {
  2633.                         DataHold = NULL;
  2634.                         DataSize = 0;
  2635.  
  2636.                         RestartSerial();
  2637.                     }
  2638.                     else
  2639.                     {
  2640.                         DataHold += Len - 1;
  2641.                         DataSize -= Len - 1;
  2642.                     }
  2643.                 }
  2644.                 else
  2645.                 {
  2646.                     ULONG Signals,SignalMask = SIG_SERIAL | SIG_TIMER | SIG_BREAK;
  2647.  
  2648.                     ClearSerial();
  2649.  
  2650.                     if(DataHold && DataSize > 0)
  2651.                     {
  2652.                         CopyMem(DataHold,Buffer,DataSize);
  2653.  
  2654.                         ReadRequest -> IOSer . io_Data        = Buffer + DataSize;
  2655.                         ReadRequest -> IOSer . io_Length    = Len - 1 - DataSize;
  2656.  
  2657.                         BytesRead = DataSize;
  2658.  
  2659.                         DataSize = 0;
  2660.                     }
  2661.                     else
  2662.                     {
  2663.                         ReadRequest -> IOSer . io_Data        = Buffer;
  2664.                         ReadRequest -> IOSer . io_Length    = Len - 1;
  2665.                     }
  2666.  
  2667.                     DataHold = NULL;
  2668.  
  2669.                     ReadRequest -> IOSer . io_Command = CMD_READ;
  2670.  
  2671.                     ClrSignal(SignalMask);
  2672.  
  2673.                     if(RexxTimeoutVal)
  2674.                         StartTime(RexxTimeoutVal,0);
  2675.  
  2676.                     SendIO(ReadRequest);
  2677.  
  2678.                     FOREVER
  2679.                     {
  2680.                         Signals = Wait(SignalMask);
  2681.  
  2682.                         if(Signals & SIG_SERIAL)
  2683.                         {
  2684.                             if(RexxTimeoutVal)
  2685.                                 StopTime();
  2686.  
  2687.                                 /* Did the request terminate gracefully? */
  2688.  
  2689.                             if(!WaitIO(ReadRequest))
  2690.                             {
  2691.                                 BytesIn += ReadRequest -> IOSer . io_Actual;
  2692.  
  2693.                                 BytesRead = ReadRequest -> IOSer . io_Actual;
  2694.                             }
  2695.                             else
  2696.                                 Results[0] = RC_ERROR;
  2697.  
  2698.                             break;
  2699.                         }
  2700.  
  2701.                         if(Signals & SIG_BREAK)
  2702.                         {
  2703.                             if(!CheckIO(ReadRequest))
  2704.                                 AbortIO(ReadRequest);
  2705.  
  2706.                             WaitIO(ReadRequest);
  2707.  
  2708.                             if(RexxTimeoutVal)
  2709.                                 StopTime();
  2710.  
  2711.                             Results[0] = RC_WARN;
  2712.  
  2713.                             break;
  2714.                         }
  2715.  
  2716.                         if(Signals & SIG_TIMER)
  2717.                         {
  2718.                             if(!CheckIO(ReadRequest))
  2719.                                 AbortIO(ReadRequest);
  2720.  
  2721.                             WaitIO(ReadRequest);
  2722.  
  2723.                             WaitIO(TimeRequest);
  2724.  
  2725.                             if(ReadRequest -> IOSer . io_Actual)
  2726.                             {
  2727.                                 BytesIn += ReadRequest -> IOSer . io_Actual;
  2728.  
  2729.                                 BytesRead = ReadRequest -> IOSer . io_Actual;
  2730.                             }
  2731.                             else
  2732.                             {
  2733.                                 WriteRequest -> IOSer . io_Command = SDCMD_QUERY;
  2734.  
  2735.                                 DoIO(WriteRequest);
  2736.  
  2737.                                 if(WriteRequest -> IOSer . io_Actual)
  2738.                                 {
  2739.                                         /* Don't read more than actually wanted. */
  2740.  
  2741.                                     ReadRequest -> IOSer . io_Command    = CMD_READ;
  2742.                                     ReadRequest -> IOSer . io_Data        = Buffer;
  2743.                                     ReadRequest -> IOSer . io_Length    = MIN(Len - 1,WriteRequest -> IOSer . io_Actual);
  2744.  
  2745.                                     if(!DoIO(ReadRequest))
  2746.                                     {
  2747.                                         BytesIn += ReadRequest -> IOSer . io_Actual;
  2748.  
  2749.                                         BytesRead = ReadRequest -> IOSer . io_Actual;
  2750.                                     }
  2751.                                 }
  2752.                             }
  2753.  
  2754.                             break;
  2755.                         }
  2756.                     }
  2757.                 }
  2758.  
  2759.                 if(BytesRead)
  2760.                 {
  2761.                     Buffer[BytesRead] = 0;
  2762.  
  2763.                     Result = CreateResult(Buffer,Results);
  2764.                 }
  2765.                 else
  2766.                 {
  2767.                     Results[0] = RC_WARN;
  2768.  
  2769.                     Result = NULL;
  2770.                 }
  2771.  
  2772.                 FreeVec(Buffer);
  2773.  
  2774.                 RestartSerial();
  2775.  
  2776.                 ReleaseWindows();
  2777.  
  2778.                 return(Result);
  2779.             }
  2780.             else
  2781.             {
  2782.                 Results[0] = RC_ERROR;
  2783.                 Results[1] = ERROR_NO_FREE_STORE;
  2784.             }
  2785.  
  2786.             RestartSerial();
  2787.         }
  2788.         else
  2789.         {
  2790.             ULONG     Signals,SignalMask = SIG_SERIAL | SIG_TIMER | SIG_BREAK;
  2791.             UBYTE    *Char = ReadBuffer;
  2792.             BYTE     Echo,Done = FALSE;
  2793.             LONG     Index = 0;
  2794.  
  2795.             if(Args[ARG_READ_NOECHO])
  2796.                 Echo = FALSE;
  2797.             else
  2798.                 Echo = TRUE;
  2799.  
  2800.             if(RexxTimeoutVal)
  2801.                 StartTime(RexxTimeoutVal,0);
  2802.  
  2803.             if(DataHold)
  2804.             {
  2805.                 while(DataSize-- > 0)
  2806.                 {
  2807.                     Char = DataHold++;
  2808.  
  2809.                     switch(*Char)
  2810.                     {
  2811.                         case '\n':
  2812.  
  2813.                             break;
  2814.  
  2815.                         case '\r':
  2816.  
  2817.                             Done = TRUE;
  2818.  
  2819.                             if(Echo)
  2820.                                 SerWrite(ReadBuffer,1);
  2821.  
  2822.                             break;
  2823.  
  2824.                         case '\b':
  2825.  
  2826.                             if(Index > 0)
  2827.                             {
  2828.                                 Index--;
  2829.  
  2830.                                 if(Echo)
  2831.                                     SerWrite(ReadBuffer,1);
  2832.                             }
  2833.  
  2834.                             break;
  2835.  
  2836.                         case '\30':
  2837.  
  2838.                             if(Echo)
  2839.                             {
  2840.                                 while(Index > 0)
  2841.                                 {
  2842.                                     Index--;
  2843.  
  2844.                                     SerWrite("\b",1);
  2845.                                 }
  2846.                             }
  2847.                             else
  2848.                                 Index = 0;
  2849.  
  2850.                         default:
  2851.  
  2852.                             if(Index < 255 && ((*Char >= ' ' && *Char < 127) || *Char >= 160 || Config -> TerminalConfig -> FontMode == FONT_IBM))
  2853.                             {
  2854.                                 SharedBuffer[Index++] = *Char;
  2855.  
  2856.                                 if(Echo)
  2857.                                     SerWrite(ReadBuffer,1);
  2858.                             }
  2859.  
  2860.                             break;
  2861.                     }
  2862.                 }
  2863.  
  2864.                 RestartSerial();
  2865.  
  2866.                 DataHold = NULL;
  2867.             }
  2868.  
  2869.             if(CheckIO(ReadRequest))
  2870.                 Signals = SIG_SERIAL;
  2871.             else
  2872.                 Signals = NULL;
  2873.  
  2874.             do
  2875.             {
  2876.                 if(Signals & SIG_SERIAL)
  2877.                 {
  2878.                     if(!WaitIO(ReadRequest))
  2879.                     {
  2880.                         BytesIn++;
  2881.  
  2882.                         switch(*Char)
  2883.                         {
  2884.                             case '\n':
  2885.  
  2886.                                 break;
  2887.  
  2888.                             case '\r':
  2889.  
  2890.                                 Done = TRUE;
  2891.  
  2892.                                 if(Echo)
  2893.                                     SerWrite(ReadBuffer,1);
  2894.  
  2895.                                 break;
  2896.  
  2897.                             case '\b':
  2898.  
  2899.                                 if(Index > 0)
  2900.                                 {
  2901.                                     Index--;
  2902.  
  2903.                                     if(Echo)
  2904.                                         SerWrite(ReadBuffer,1);
  2905.                                 }
  2906.  
  2907.                                 break;
  2908.  
  2909.                             case '\30':
  2910.  
  2911.                                 if(Echo)
  2912.                                 {
  2913.                                     while(Index > 0)
  2914.                                     {
  2915.                                         Index--;
  2916.  
  2917.                                         SerWrite("\b",1);
  2918.                                     }
  2919.                                 }
  2920.                                 else
  2921.                                     Index = 0;
  2922.  
  2923.                             default:
  2924.  
  2925.                                 if(Index < 255 && ((*Char >= ' ' && *Char < 127) || *Char >= 160 || Config -> TerminalConfig -> FontMode == FONT_IBM))
  2926.                                 {
  2927.                                     SharedBuffer[Index++] = *Char;
  2928.  
  2929.                                     if(Echo)
  2930.                                         SerWrite(ReadBuffer,1);
  2931.                                 }
  2932.  
  2933.                                 break;
  2934.                         }
  2935.                     }
  2936.  
  2937.                     RestartSerial();
  2938.                 }
  2939.  
  2940.                 if(Signals & (SIG_BREAK | SIG_TIMER))
  2941.                 {
  2942.                     Results[0] = RC_WARN;
  2943.  
  2944.                     break;
  2945.                 }
  2946.  
  2947.                 if(!Done)
  2948.                     Signals = Wait(SignalMask);
  2949.             }
  2950.             while(!Done);
  2951.  
  2952.             if(RexxTimeoutVal)
  2953.                 StopTime();
  2954.  
  2955.             if(Index)
  2956.             {
  2957.                 SharedBuffer[Index] = 0;
  2958.  
  2959.                 ReleaseWindows();
  2960.  
  2961.                 return(CreateResult(SharedBuffer,Results));
  2962.             }
  2963.             else
  2964.                 Results[0] = RC_WARN;
  2965.         }
  2966.     }
  2967.     else
  2968.     {
  2969.         if(Args[ARG_READ_NUM])
  2970.         {
  2971.             STRPTR Buffer;
  2972.  
  2973.             if(Buffer = (STRPTR)AllocVec(Len,MEMF_ANY))
  2974.             {
  2975.                 STRPTR Result;
  2976.  
  2977.                 if(DataHold && DataSize >= Len - 1)
  2978.                 {
  2979.                     CopyMem(DataHold,Buffer,Len - 1);
  2980.  
  2981.                     BytesRead = Len - 1;
  2982.  
  2983.                     if(Len - 1 == DataSize)
  2984.                     {
  2985.                         DataHold = NULL;
  2986.                         DataSize = 0;
  2987.  
  2988.                         RestartSerial();
  2989.                     }
  2990.                     else
  2991.                     {
  2992.                         DataHold += Len - 1;
  2993.                         DataSize -= Len - 1;
  2994.                     }
  2995.                 }
  2996.                 else
  2997.                 {
  2998.                     ULONG Signals,SignalMask = SIG_SERIAL | SIG_TIMER | SIG_BREAK;
  2999.  
  3000.                     ClearSerial();
  3001.  
  3002.                     if(DataHold && DataSize > 0)
  3003.                     {
  3004.                         CopyMem(DataHold,Buffer,DataSize);
  3005.  
  3006.                         ReadRequest -> IOSer . io_Data        = Buffer + DataSize;
  3007.                         ReadRequest -> IOSer . io_Length    = Len - 1 - DataSize;
  3008.  
  3009.                         BytesRead = DataSize;
  3010.  
  3011.                         DataSize = 0;
  3012.                     }
  3013.                     else
  3014.                     {
  3015.                         ReadRequest -> IOSer . io_Data        = Buffer;
  3016.                         ReadRequest -> IOSer . io_Length    = Len - 1;
  3017.                     }
  3018.  
  3019.                     DataHold = NULL;
  3020.  
  3021.                     ReadRequest -> IOSer . io_Command = CMD_READ;
  3022.  
  3023.                     ClrSignal(SignalMask);
  3024.  
  3025.                     if(RexxTimeoutVal)
  3026.                         StartTime(RexxTimeoutVal,0);
  3027.  
  3028.                     SendIO(ReadRequest);
  3029.  
  3030.                     FOREVER
  3031.                     {
  3032.                         Signals = Wait(SignalMask);
  3033.  
  3034.                         if(Signals & SIG_SERIAL)
  3035.                         {
  3036.                             if(RexxTimeoutVal)
  3037.                                 StopTime();
  3038.  
  3039.                                 /* Did the request terminate gracefully? */
  3040.  
  3041.                             if(!WaitIO(ReadRequest))
  3042.                             {
  3043.                                 BytesIn += ReadRequest -> IOSer . io_Actual;
  3044.  
  3045.                                 BytesRead = ReadRequest -> IOSer . io_Actual;
  3046.                             }
  3047.                             else
  3048.                                 Results[0] = RC_ERROR;
  3049.  
  3050.                             break;
  3051.                         }
  3052.  
  3053.                         if(Signals & SIG_BREAK)
  3054.                         {
  3055.                             if(!CheckIO(ReadRequest))
  3056.                                 AbortIO(ReadRequest);
  3057.  
  3058.                             WaitIO(ReadRequest);
  3059.  
  3060.                             if(RexxTimeoutVal)
  3061.                                 StopTime();
  3062.  
  3063.                             Results[0] = RC_WARN;
  3064.  
  3065.                             break;
  3066.                         }
  3067.  
  3068.                         if(Signals & SIG_TIMER)
  3069.                         {
  3070.                             if(!CheckIO(ReadRequest))
  3071.                                 AbortIO(ReadRequest);
  3072.  
  3073.                             WaitIO(ReadRequest);
  3074.  
  3075.                             WaitIO(TimeRequest);
  3076.  
  3077.                             if(ReadRequest -> IOSer . io_Actual)
  3078.                             {
  3079.                                 BytesIn += ReadRequest -> IOSer . io_Actual;
  3080.  
  3081.                                 BytesRead = ReadRequest -> IOSer . io_Actual;
  3082.                             }
  3083.                             else
  3084.                             {
  3085.                                 WriteRequest -> IOSer . io_Command = SDCMD_QUERY;
  3086.  
  3087.                                 DoIO(WriteRequest);
  3088.  
  3089.                                 if(WriteRequest -> IOSer . io_Actual)
  3090.                                 {
  3091.                                         /* Don't read more than actually wanted. */
  3092.  
  3093.                                     ReadRequest -> IOSer . io_Command    = CMD_READ;
  3094.                                     ReadRequest -> IOSer . io_Data        = Buffer;
  3095.                                     ReadRequest -> IOSer . io_Length    = MIN(Len - 1,WriteRequest -> IOSer . io_Actual);
  3096.  
  3097.                                     if(!DoIO(ReadRequest))
  3098.                                     {
  3099.                                         BytesIn += ReadRequest -> IOSer . io_Actual;
  3100.  
  3101.                                         BytesRead = ReadRequest -> IOSer . io_Actual;
  3102.                                     }
  3103.                                 }
  3104.                             }
  3105.  
  3106.                             break;
  3107.                         }
  3108.                     }
  3109.                 }
  3110.  
  3111.                 if(BytesRead)
  3112.                 {
  3113.                     STRPTR MetaBuffer;
  3114.  
  3115.                     if(MetaBuffer = AllocVec(Len,MEMF_ANY))
  3116.                     {
  3117.                         struct TranslationHandle    Handle;
  3118.                         LONG                Bytes;
  3119.  
  3120.                         TranslateSetup(&Handle,Buffer,BytesRead,MetaBuffer,Len - 1,ReceiveTable);
  3121.  
  3122.                         Bytes = TranslateBuffer(&Handle);
  3123.  
  3124.                         MetaBuffer[Bytes] = 0;
  3125.  
  3126.                         Result = CreateResult(MetaBuffer,Results);
  3127.  
  3128.                         FreeVec(MetaBuffer);
  3129.                     }
  3130.                     else
  3131.                     {
  3132.                         Results[0] = RC_ERROR;
  3133.                         Results[1] = ERROR_NO_FREE_STORE;
  3134.  
  3135.                         Result = NULL;
  3136.                     }
  3137.                 }
  3138.                 else
  3139.                 {
  3140.                     Results[0] = RC_WARN;
  3141.  
  3142.                     Result = NULL;
  3143.                 }
  3144.  
  3145.                 FreeVec(Buffer);
  3146.  
  3147.                 RestartSerial();
  3148.  
  3149.                 ReleaseWindows();
  3150.  
  3151.                 return(Result);
  3152.             }
  3153.             else
  3154.             {
  3155.                 Results[0] = RC_ERROR;
  3156.                 Results[1] = ERROR_NO_FREE_STORE;
  3157.             }
  3158.  
  3159.             RestartSerial();
  3160.         }
  3161.         else
  3162.         {
  3163.             ULONG                 Signals,SignalMask = SIG_SERIAL | SIG_TIMER | SIG_BREAK;
  3164.             UBYTE                *Char = ReadBuffer,Temp;
  3165.             BYTE                 Echo,Done = FALSE;
  3166.             LONG                 Index = 0;
  3167.             struct TranslationHandle     Handle;
  3168.  
  3169.             if(Args[ARG_READ_NOECHO])
  3170.                 Echo = FALSE;
  3171.             else
  3172.                 Echo = TRUE;
  3173.  
  3174.             if(RexxTimeoutVal)
  3175.                 StartTime(RexxTimeoutVal,0);
  3176.  
  3177.             if(DataHold)
  3178.             {
  3179.                 while(DataSize-- > 0)
  3180.                 {
  3181.                     Char = DataHold++;
  3182.  
  3183.                     TranslateSetup(&Handle,Char,1,&Temp,1,ReceiveTable);
  3184.  
  3185.                     while(!Done && TranslateBuffer(&Handle))
  3186.                     {
  3187.                         switch(Temp)
  3188.                         {
  3189.                             case '\n':
  3190.  
  3191.                                 break;
  3192.  
  3193.                             case '\r':
  3194.  
  3195.                                 Done = TRUE;
  3196.  
  3197.                                 if(Echo)
  3198.                                     SerWrite(&Temp,1);
  3199.  
  3200.                                 break;
  3201.  
  3202.                             case '\b':
  3203.  
  3204.                                 if(Index > 0)
  3205.                                 {
  3206.                                     Index--;
  3207.  
  3208.                                     if(Echo)
  3209.                                         SerWrite(&Temp,1);
  3210.                                 }
  3211.  
  3212.                                 break;
  3213.  
  3214.                             case '\30':
  3215.  
  3216.                                 if(Echo)
  3217.                                 {
  3218.                                     while(Index > 0)
  3219.                                     {
  3220.                                         Index--;
  3221.  
  3222.                                         SerWrite("\b",1);
  3223.                                     }
  3224.                                 }
  3225.                                 else
  3226.                                     Index = 0;
  3227.  
  3228.                             default:
  3229.  
  3230.                                 if(Index < 255 && ((Temp >= ' ' && Temp < 127) || Temp >= 160 || Config -> TerminalConfig -> FontMode == FONT_IBM))
  3231.                                 {
  3232.                                     SharedBuffer[Index++] = Temp;
  3233.  
  3234.                                     if(Echo)
  3235.                                         SerWrite(&Temp,1);
  3236.                                 }
  3237.  
  3238.                                 break;
  3239.                         }
  3240.                     }
  3241.                 }
  3242.  
  3243.                 RestartSerial();
  3244.  
  3245.                 DataHold = NULL;
  3246.             }
  3247.  
  3248.             if(CheckIO(ReadRequest))
  3249.                 Signals = SIG_SERIAL;
  3250.             else
  3251.                 Signals = NULL;
  3252.  
  3253.             do
  3254.             {
  3255.                 if(Signals & SIG_SERIAL)
  3256.                 {
  3257.                     if(!WaitIO(ReadRequest))
  3258.                     {
  3259.                         BytesIn++;
  3260.  
  3261.                         TranslateSetup(&Handle,Char,1,&Temp,1,ReceiveTable);
  3262.  
  3263.                         while(!Done && TranslateBuffer(&Handle))
  3264.                         {
  3265.                             switch(Temp)
  3266.                             {
  3267.                                 case '\n':
  3268.  
  3269.                                     break;
  3270.  
  3271.                                 case '\r':
  3272.  
  3273.                                     Done = TRUE;
  3274.  
  3275.                                     if(Echo)
  3276.                                         SerWrite(&Temp,1);
  3277.  
  3278.                                     break;
  3279.  
  3280.                                 case '\b':
  3281.  
  3282.                                     if(Index > 0)
  3283.                                     {
  3284.                                         Index--;
  3285.  
  3286.                                         if(Echo)
  3287.                                             SerWrite(&Temp,1);
  3288.                                     }
  3289.  
  3290.                                     break;
  3291.  
  3292.                                 case '\30':
  3293.  
  3294.                                     if(Echo)
  3295.                                     {
  3296.                                         while(Index > 0)
  3297.                                         {
  3298.                                             Index--;
  3299.  
  3300.                                             SerWrite("\b",1);
  3301.                                         }
  3302.                                     }
  3303.                                     else
  3304.                                         Index = 0;
  3305.  
  3306.                                 default:
  3307.  
  3308.                                     if(Index < 255 && ((Temp >= ' ' && Temp < 127) || Temp >= 160 || Config -> TerminalConfig -> FontMode == FONT_IBM))
  3309.                                     {
  3310.                                         SharedBuffer[Index++] = Temp;
  3311.  
  3312.                                         if(Echo)
  3313.                                             SerWrite(&Temp,1);
  3314.                                     }
  3315.  
  3316.                                     break;
  3317.                             }
  3318.                         }
  3319.                     }
  3320.  
  3321.                     RestartSerial();
  3322.                 }
  3323.  
  3324.                 if(Signals & (SIG_BREAK | SIG_TIMER))
  3325.                 {
  3326.                     Results[0] = RC_WARN;
  3327.  
  3328.                     break;
  3329.                 }
  3330.  
  3331.                 if(!Done)
  3332.                     Signals = Wait(SignalMask);
  3333.             }
  3334.             while(!Done);
  3335.  
  3336.             if(RexxTimeoutVal)
  3337.                 StopTime();
  3338.  
  3339.             if(Index)
  3340.             {
  3341.                 SharedBuffer[Index] = 0;
  3342.  
  3343.                 ReleaseWindows();
  3344.  
  3345.                 return(CreateResult(SharedBuffer,Results));
  3346.             }
  3347.             else
  3348.                 Results[0] = RC_WARN;
  3349.         }
  3350.     }
  3351.  
  3352.     ReleaseWindows();
  3353.  
  3354.     return(NULL);
  3355. }
  3356.  
  3357. STRPTR __regargs
  3358. RexxReceiveFile(struct RexxPkt *Pkt)
  3359. {
  3360.     enum    {    ARG_RECEIVEFILE_MODE,ARG_RECEIVEFILE_NAME };
  3361.  
  3362.     WORD Mode = TRANSFER_BINARY;
  3363.  
  3364.     if(Args[ARG_RECEIVEFILE_MODE])
  3365.         Mode = ToMode(Args[ARG_RECEIVEFILE_MODE]);
  3366.  
  3367.     if(Mode == -1)
  3368.     {
  3369.         Results[0] = RC_ERROR;
  3370.         Results[1] = ERROR_ACTION_NOT_KNOWN;
  3371.     }
  3372.     else
  3373.     {
  3374.         BlockWindows();
  3375.  
  3376.         switch(Mode)
  3377.         {
  3378.             case TRANSFER_ASCII:
  3379.  
  3380.                 if(ChangeProtocol(Config -> TransferConfig -> ASCIIDownloadLibrary))
  3381.                 {
  3382.                     BinaryTransfer = FALSE;
  3383.  
  3384.                     StartXprReceive(TRANSFER_ASCII,NULL,FALSE);
  3385.  
  3386.                     BinaryTransfer = TRUE;
  3387.  
  3388.                     LocalRexxSerialCommand(Config -> CommandConfig -> DownloadMacro,NULL);
  3389.                 }
  3390.                 else
  3391.                 {
  3392.                     Results[0] = RC_ERROR;
  3393.                     Results[1] = ERROR_NO_FREE_STORE;
  3394.                 }
  3395.  
  3396.                 ResetProtocol();
  3397.  
  3398.                 break;
  3399.  
  3400.             case TRANSFER_TEXT:
  3401.  
  3402.                 if(ChangeProtocol(Config -> TransferConfig -> TextDownloadLibrary))
  3403.                 {
  3404.                     BinaryTransfer = FALSE;
  3405.  
  3406.                     StartXprReceive(TRANSFER_TEXT,NULL,FALSE);
  3407.  
  3408.                     BinaryTransfer = TRUE;
  3409.  
  3410.                     LocalRexxSerialCommand(Config -> CommandConfig -> DownloadMacro,NULL);
  3411.                 }
  3412.                 else
  3413.                 {
  3414.                     Results[0] = RC_ERROR;
  3415.                     Results[1] = ERROR_NO_FREE_STORE;
  3416.                 }
  3417.  
  3418.                 ResetProtocol();
  3419.  
  3420.                 break;
  3421.  
  3422.             case TRANSFER_BINARY:
  3423.  
  3424.                 if(ChangeProtocol(Config -> TransferConfig -> BinaryDownloadLibrary))
  3425.                 {
  3426.                     BinaryTransfer = TRUE;
  3427.  
  3428.                     StartXprReceive(TRANSFER_BINARY,NULL,FALSE);
  3429.  
  3430.                     LocalRexxSerialCommand(Config -> CommandConfig -> DownloadMacro,NULL);
  3431.                 }
  3432.                 else
  3433.                 {
  3434.                     Results[0] = RC_ERROR;
  3435.                     Results[1] = ERROR_NO_FREE_STORE;
  3436.                 }
  3437.  
  3438.                 ResetProtocol();
  3439.  
  3440.                 break;
  3441.         }
  3442.  
  3443.         if(TransferFailed)
  3444.             Results[0] = RC_ERROR;
  3445.  
  3446.         if(TransferAborted)
  3447.             Results[0] = RC_WARN;
  3448.  
  3449.         ReleaseWindows();
  3450.     }
  3451.  
  3452.     return(NULL);
  3453. }
  3454.  
  3455. STRPTR __regargs
  3456. RexxRedial(struct RexxPkt *Pkt)
  3457. {
  3458.     if(DialList)
  3459.     {
  3460.         if(DialList -> lh_Head -> ln_Succ)
  3461.             DoDial = DIAL_REDIAL;
  3462.         else
  3463.             Results[0] = RC_WARN;
  3464.     }
  3465.     else
  3466.         Results[0] = RC_WARN;
  3467.  
  3468.     return(NULL);
  3469. }
  3470.  
  3471. STRPTR __regargs
  3472. RexxRemove(struct RexxPkt *Pkt)
  3473. {
  3474.     enum    {    ARG_REMOVE_FROM,ARG_REMOVE_NAME };
  3475.  
  3476.     WORD Index;
  3477.  
  3478.     if((Index = ToList(Args[ARG_REMOVE_FROM])) == -1)
  3479.     {
  3480.         Results[0] = RC_ERROR;
  3481.         Results[1] = TERMERROR_UNKNOWN_LIST;
  3482.     }
  3483.     else
  3484.     {
  3485.         if(Args[ARG_REMOVE_NAME] && Index == GLIST_DIAL)
  3486.         {
  3487.             Results[0] = RC_ERROR;
  3488.             Results[1] = TERMERROR_DATA_TYPES_INCOMPATIBLE;
  3489.         }
  3490.         else
  3491.         {
  3492.             struct GenericList *List;
  3493.  
  3494.             List = GenericListTable[Index];
  3495.  
  3496.             if(Args[ARG_REMOVE_NAME])
  3497.             {
  3498.                 STRPTR Buffer;
  3499.  
  3500.                 if(Buffer = CreateMatchBuffer(Args[ARG_REMOVE_NAME]))
  3501.                 {
  3502.                     struct Node *Node,*NextNode;
  3503.  
  3504.                     ObtainSemaphore(&List -> ListSemaphore);
  3505.  
  3506.                     Node = (struct Node *)List -> ListHeader . mlh_Head;
  3507.  
  3508.                     while(NextNode = Node -> ln_Succ)
  3509.                     {
  3510.                         if(MatchBuffer(Buffer,Node -> ln_Name))
  3511.                         {
  3512.                             Forbid();
  3513.  
  3514.                             ReleaseSemaphore(&List -> ListSemaphore);
  3515.  
  3516.                             DeleteGenericListNode(List,Node);
  3517.  
  3518.                             ObtainSemaphore(&List -> ListSemaphore);
  3519.  
  3520.                             Permit();
  3521.                         }
  3522.  
  3523.                         Node = NextNode;
  3524.                     }
  3525.  
  3526.                     ReleaseSemaphore(&List -> ListSemaphore);
  3527.  
  3528.                     DeleteMatchBuffer(Buffer);
  3529.                 }
  3530.                 else
  3531.                 {
  3532.                     Results[0] = RC_ERROR;
  3533.                     Results[1] = ERROR_NO_FREE_STORE;
  3534.                 }
  3535.             }
  3536.             else
  3537.                 DeleteGenericListNode(List,NULL);
  3538.  
  3539.             if(!GenericListCount(List))
  3540.                 Results[0] = RC_WARN;
  3541.         }
  3542.     }
  3543.  
  3544.     return(NULL);
  3545. }
  3546.  
  3547. STRPTR __regargs
  3548. RexxRequestFile(struct RexxPkt *Pkt)
  3549. {
  3550.     enum    {    ARG_REQUESTFILE_TITLE,ARG_REQUESTFILE_PATH,ARG_REQUESTFILE_FILE,
  3551.             ARG_REQUESTFILE_PATTERN,ARG_REQUESTFILE_MULTI,ARG_REQUESTFILE_NAME };
  3552.  
  3553.     if(Args[ARG_REQUESTFILE_MULTI] && !Args[ARG_REQUESTFILE_NAME])
  3554.     {
  3555.         Results[0] = RC_ERROR;
  3556.         Results[1] = TERMERROR_RESULT_VARIABLE_REQUIRED;
  3557.     }
  3558.     else
  3559.     {
  3560.         struct FileRequester    *FileRequester;
  3561.         UBYTE             DummyBuffer[MAX_FILENAME_LENGTH],
  3562.                     *DummyChar;
  3563.         STRPTR             FileName,
  3564.                      PathName;
  3565.  
  3566.         if(Args[ARG_REQUESTFILE_PATH])
  3567.         {
  3568.             PathName = Args[ARG_REQUESTFILE_PATH];
  3569.  
  3570.             if(Args[ARG_REQUESTFILE_FILE])
  3571.                 FileName = Args[ARG_REQUESTFILE_FILE];
  3572.             else
  3573.                 FileName = "";
  3574.         }
  3575.         else
  3576.         {
  3577.             PathName = "";
  3578.  
  3579.             if(Args[ARG_REQUESTFILE_FILE])
  3580.             {
  3581.                 strcpy(DummyBuffer,Args[ARG_REQUESTFILE_FILE]);
  3582.  
  3583.                 DummyChar = PathPart(DummyBuffer);
  3584.  
  3585.                 *DummyChar = 0;
  3586.  
  3587.                 PathName = DummyBuffer;
  3588.                 FileName = FilePart(Args[ARG_REQUESTFILE_FILE]);
  3589.             }
  3590.             else
  3591.                 FileName = "";
  3592.         }
  3593.  
  3594.         BlockWindows();
  3595.  
  3596.         if(FileRequester = GetFile(Args[ARG_REQUESTFILE_TITLE],PathName,FileName,DummyBuffer,Args[ARG_REQUESTFILE_PATTERN],FALSE,Args[ARG_REQUESTFILE_MULTI] != NULL,FALSE,"Ok",TRUE))
  3597.         {
  3598.             if(Args[ARG_REQUESTFILE_NAME])
  3599.             {
  3600.                 if(Args[ARG_REQUESTFILE_MULTI])
  3601.                 {
  3602.                     UBYTE         DummyBuffer[MAX_FILENAME_LENGTH];
  3603.                     struct WBArg    *ArgList = FileRequester -> rf_ArgList;
  3604.                     LONG         i,Counted = 0;
  3605.  
  3606.                     for(i = 0 ; i < FileRequester -> rf_NumArgs ; i++)
  3607.                     {
  3608.                         if(ArgList[i] . wa_Name)
  3609.                         {
  3610.                             if(ArgList[i] . wa_Lock)
  3611.                             {
  3612.                                 if(!NameFromLock(ArgList[i] . wa_Lock,DummyBuffer,MAX_FILENAME_LENGTH))
  3613.                                 {
  3614.                                     Results[0] = RC_ERROR;
  3615.                                     Results[1] = IoErr();
  3616.  
  3617.                                     break;
  3618.                                 }
  3619.                             }
  3620.                             else
  3621.                                 strcpy(DummyBuffer,FileRequester -> rf_Dir);
  3622.  
  3623.                             if(AddPart(DummyBuffer,ArgList[i] . wa_Name,MAX_FILENAME_LENGTH))
  3624.                             {
  3625.                                 if(CreateVarArgs(DummyBuffer,Pkt,"%s.%ld",Args[ARG_REQUESTFILE_NAME],i))
  3626.                                     Counted++;
  3627.                                 else
  3628.                                     break;
  3629.                             }
  3630.                             else
  3631.                             {
  3632.                                 Results[0] = RC_ERROR;
  3633.                                 Results[1] = IoErr();
  3634.  
  3635.                                 break;
  3636.                             }
  3637.                         }
  3638.                     }
  3639.  
  3640.                     if(Counted)
  3641.                     {
  3642.                         SPrintf(DummyBuffer,"%ld",Counted);
  3643.  
  3644.                         CreateVarArgs(DummyBuffer,Pkt,"%s.COUNT",Args[ARG_REQUESTFILE_NAME]);
  3645.                     }
  3646.  
  3647.                     FreeAslRequest(FileRequester);
  3648.                 }
  3649.                 else
  3650.                 {
  3651.                     FreeAslRequest(FileRequester);
  3652.  
  3653.                     ReleaseWindows();
  3654.  
  3655.                     return(CreateVar(DummyBuffer,Pkt,Args[ARG_REQUESTFILE_NAME]));
  3656.                 }
  3657.             }
  3658.             else
  3659.             {
  3660.                 FreeAslRequest(FileRequester);
  3661.  
  3662.                 ReleaseWindows();
  3663.  
  3664.                 return(CreateResult(DummyBuffer,Results));
  3665.             }
  3666.         }
  3667.         else
  3668.             Results[0] = RC_WARN;
  3669.  
  3670.         ReleaseWindows();
  3671.     }
  3672.  
  3673.     return(NULL);
  3674. }
  3675.  
  3676. STRPTR __regargs
  3677. RexxRequestNotify(struct RexxPkt *Pkt)
  3678. {
  3679.     enum    {    ARG_REQUESTNOTIFY_TITLE,ARG_REQUESTNOTIFY_PROMPT };
  3680.  
  3681.     struct EasyStruct    Easy;
  3682.     ULONG            IDCMP = NULL;
  3683.  
  3684.     Easy . es_StructSize    = sizeof(struct EasyStruct);
  3685.     Easy . es_Flags        = NULL;
  3686.     Easy . es_TextFormat    = Args[ARG_REQUESTNOTIFY_PROMPT];
  3687.     Easy . es_GadgetFormat    = LocaleString(MSG_GLOBAL_CONTINUE_TXT);
  3688.  
  3689.     if(Args[ARG_REQUESTNOTIFY_TITLE])
  3690.         Easy . es_Title    = Args[ARG_REQUESTNOTIFY_TITLE];
  3691.     else
  3692.         Easy . es_Title    = LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  3693.  
  3694.     BlockWindows();
  3695.  
  3696.     EasyRequestArgs(Window,&Easy,&IDCMP,NULL);
  3697.  
  3698.     ReleaseWindows();
  3699.  
  3700.     return(NULL);
  3701. }
  3702.  
  3703. STRPTR __regargs
  3704. RexxRequestNumber(struct RexxPkt *Pkt)
  3705. {
  3706.     enum    {    ARG_REQUESTNUMBER_DEFAULT,ARG_REQUESTNUMBER_PROMPT };
  3707.  
  3708.     UBYTE DummyBuffer[256];
  3709.  
  3710.     if(Args[ARG_REQUESTNUMBER_DEFAULT])
  3711.         SPrintf(DummyBuffer,"%ld",*(LONG *)Args[ARG_REQUESTNUMBER_DEFAULT]);
  3712.     else
  3713.         DummyBuffer[0] = 0;
  3714.  
  3715.     BlockWindows();
  3716.  
  3717.     if(GetString(FALSE,FALSE,255,Args[ARG_REQUESTNUMBER_PROMPT],DummyBuffer))
  3718.     {
  3719.         STRPTR Index = DummyBuffer;
  3720.  
  3721.         while(*Index == ' ' || *Index == '\t')
  3722.             Index++;
  3723.  
  3724.         if(*Index)
  3725.         {
  3726.             LONG Value;
  3727.  
  3728.             if(StrToLong(DummyBuffer,&Value) == -1)
  3729.             {
  3730.                 Results[0] = RC_ERROR;
  3731.                 Results[1] = ERROR_BAD_NUMBER;
  3732.             }
  3733.             else
  3734.             {
  3735.                 ReleaseWindows();
  3736.  
  3737.                 SPrintf(DummyBuffer,"%ld",Value);
  3738.  
  3739.                 return(CreateResult(DummyBuffer,Results));
  3740.             }
  3741.         }
  3742.         else
  3743.             Results[0] = RC_WARN;
  3744.     }
  3745.     else
  3746.         Results[0] = RC_WARN;
  3747.  
  3748.     ReleaseWindows();
  3749.  
  3750.     return(NULL);
  3751. }
  3752.  
  3753. STRPTR __regargs
  3754. RexxRequestResponse(struct RexxPkt *Pkt)
  3755. {
  3756.     enum    {    ARG_REQUESTRESPONSE_TITLE,ARG_REQUESTRESPONSE_OPTIONS,
  3757.             ARG_REQUESTRESPONSE_PROMPT };
  3758.  
  3759.     struct EasyStruct    Easy;
  3760.     ULONG            IDCMP = NULL;
  3761.     WORD            Result;
  3762.  
  3763.     Easy . es_StructSize    = sizeof(struct EasyStruct);
  3764.     Easy . es_Flags        = NULL;
  3765.     Easy . es_TextFormat    = Args[ARG_REQUESTRESPONSE_PROMPT];
  3766.  
  3767.     if(Args[ARG_REQUESTRESPONSE_OPTIONS])
  3768.         Easy . es_GadgetFormat = Args[ARG_REQUESTRESPONSE_OPTIONS];
  3769.     else
  3770.         Easy . es_GadgetFormat = LocaleString(MSG_GLOBAL_YES_NO_TXT);
  3771.  
  3772.     if(Args[ARG_REQUESTRESPONSE_TITLE])
  3773.         Easy . es_Title    = Args[ARG_REQUESTRESPONSE_TITLE];
  3774.     else
  3775.         Easy . es_Title    = LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  3776.  
  3777.     BlockWindows();
  3778.  
  3779.     Result = EasyRequestArgs(Window,&Easy,&IDCMP,NULL);
  3780.  
  3781.     ReleaseWindows();
  3782.  
  3783.     if(Result)
  3784.     {
  3785.         UBYTE DummyBuffer[20];
  3786.  
  3787.         SPrintf(DummyBuffer,"%ld",Result);
  3788.  
  3789.         return(CreateResult(DummyBuffer,Results));
  3790.     }
  3791.     else
  3792.     {
  3793.         Results[0] = RC_WARN;
  3794.  
  3795.         return(NULL);
  3796.     }
  3797. }
  3798.  
  3799. STRPTR __regargs
  3800. RexxRequestString(struct RexxPkt *Pkt)
  3801. {
  3802.     enum    {    ARG_REQUESTSTRING_SECRET,ARG_REQUESTSTRING_DEFAULT,ARG_REQUESTSTRING_PROMPT };
  3803.  
  3804.     UBYTE DummyBuffer[256];
  3805.  
  3806.     if(Args[ARG_REQUESTSTRING_DEFAULT])
  3807.         strcpy(DummyBuffer,Args[ARG_REQUESTSTRING_DEFAULT]);
  3808.     else
  3809.         DummyBuffer[0] = 0;
  3810.  
  3811.     BlockWindows();
  3812.  
  3813.     if(GetString(FALSE,Args[ARG_REQUESTSTRING_SECRET] != NULL,255,Args[ARG_REQUESTSTRING_PROMPT],DummyBuffer))
  3814.     {
  3815.         ReleaseWindows();
  3816.  
  3817.         return(CreateResult(DummyBuffer,Results));
  3818.     }
  3819.     else
  3820.         Results[0] = RC_WARN;
  3821.  
  3822.     ReleaseWindows();
  3823.  
  3824.     return(NULL);
  3825. }
  3826.  
  3827. STRPTR __regargs
  3828. RexxResetScreen(struct RexxPkt *Pkt)
  3829. {
  3830.     if(XEmulatorBase && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  3831.         XEmulatorResetConsole(XEM_IO);
  3832.     else
  3833.     {
  3834.         FreeMarker();
  3835.  
  3836.         ClearCursor();
  3837.  
  3838.         DoCancel();
  3839.  
  3840.         Reset();
  3841.  
  3842.         DrawCursor();
  3843.     }
  3844.  
  3845.     return(NULL);
  3846. }
  3847.  
  3848. STRPTR __regargs
  3849. RexxResetStyles(struct RexxPkt *Pkt)
  3850. {
  3851.     if(XEmulatorBase && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  3852.         XEmulatorResetTextStyles(XEM_IO);
  3853.     else
  3854.     {
  3855.         DropMarker();
  3856.  
  3857.         ClearCursor();
  3858.  
  3859.         SetAttributes("0m");
  3860.  
  3861.         Config -> EmulationConfig -> FontScale = SCALE_NORMAL;
  3862.  
  3863.         FgPen = GetPenIndex(SafeTextPen);
  3864.         BgPen = 0;
  3865.  
  3866.         if(ReadAPen(RPort) != MappedPens[0][FgPen])
  3867.             SetAPen(RPort,MappedPens[0][FgPen]);
  3868.  
  3869.         if(ReadBPen(RPort) != MappedPens[0][BgPen])
  3870.             SetBPen(RPort,MappedPens[0][BgPen]);
  3871.  
  3872.         SetWrMsk(RPort,DepthMask);
  3873.  
  3874.         ConFontScaleUpdate();
  3875.  
  3876.         DrawCursor();
  3877.     }
  3878.  
  3879.     return(NULL);
  3880. }
  3881.  
  3882. STRPTR __regargs
  3883. RexxResetText(struct RexxPkt *Pkt)
  3884. {
  3885.     if(XEmulatorBase && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  3886.         XEmulatorResetCharset(XEM_IO);
  3887.     else
  3888.     {
  3889.         DropMarker();
  3890.  
  3891.         CurrentFont = TextFont;
  3892.  
  3893.         SetFont(RPort,CurrentFont);
  3894.  
  3895.         ConOutputUpdate();
  3896.     }
  3897.  
  3898.     return(NULL);
  3899. }
  3900.  
  3901. STRPTR __regargs
  3902. RexxSaveAs(struct RexxPkt *Pkt)
  3903. {
  3904.     enum    {    ARG_SAVEAS_NAME,ARG_SAVEAS_FROM };
  3905.  
  3906.     WORD Index = ToConfig(Args[ARG_SAVEAS_FROM]);
  3907.  
  3908.     if(Index == -1)
  3909.     {
  3910.         Results[0] = RC_ERROR;
  3911.         Results[1] = ERROR_OBJECT_NOT_FOUND;
  3912.     }
  3913.     else
  3914.     {
  3915.         UBYTE    DummyBuffer[MAX_FILENAME_LENGTH];
  3916.         STRPTR    FileName;
  3917.  
  3918.         if(Args[ARG_SAVEAS_NAME])
  3919.             FileName = Args[ARG_SAVEAS_NAME];
  3920.         else
  3921.         {
  3922.             STRPTR             Title;
  3923.             struct FileRequester    *FileRequest;
  3924.  
  3925.             FileName = NULL;
  3926.  
  3927.             switch(Index)
  3928.             {
  3929.                 case DATATYPE_TRANSLATIONS:
  3930.  
  3931.                     Title = LocaleString(MSG_TRANSLATIONPANEL_SAVE_TRANSLATION_TABLES_TXT);
  3932.                     break;
  3933.  
  3934.                 case DATATYPE_FUNCTIONKEYS:
  3935.  
  3936.                     Title = LocaleString(MSG_MACROPANEL_SAVE_MACRO_KEYS_TXT);
  3937.                     break;
  3938.  
  3939.                 case DATATYPE_CURSORKEYS:
  3940.  
  3941.                     Title = LocaleString(MSG_CURSORPANEL_SAVE_CURSOR_KEYS_TXT);
  3942.                     break;
  3943.  
  3944.                 case DATATYPE_FASTMACROS:
  3945.  
  3946.                     Title = LocaleString(MSG_FASTMACROPANEL_SAVE_FAST_MACRO_SETTINGS_TXT);
  3947.                     break;
  3948.  
  3949.                 case DATATYPE_HOTKEYS:
  3950.  
  3951.                     Title = LocaleString(MSG_HOTKEYPANEL_SAVE_HOTKEYS_TXT);
  3952.                     break;
  3953.  
  3954.                 case DATATYPE_SPEECH:
  3955.  
  3956.                     Title = LocaleString(MSG_SPEECHPANEL_SAVE_SPEECH_SETTINGS_TXT);
  3957.                     break;
  3958.  
  3959.                 case DATATYPE_SOUND:
  3960.  
  3961.                     Title = LocaleString(MSG_SOUNDPANEL_SAVE_SOUNDS_TXT);
  3962.                     break;
  3963.  
  3964.                 case DATATYPE_BUFFER:
  3965.  
  3966.                     Title = LocaleString(MSG_TERMMAIN_SAVE_BUFFER_TXT);
  3967.                     break;
  3968.  
  3969.                 case DATATYPE_CONFIGURATION:
  3970.  
  3971.                     Title = LocaleString(MSG_TERMMAIN_SAVE_PREFERENCES_AS_TXT);
  3972.                     break;
  3973.  
  3974.                 case DATATYPE_PHONEBOOK:
  3975.  
  3976.                     Title = LocaleString(MSG_PHONEPANEL_SAVE_PHONEBOOK_TXT);
  3977.                     break;
  3978.  
  3979.                 case DATATYPE_SCREENTEXT:
  3980.  
  3981.                     Title = LocaleString(MSG_TERMMAIN_SAVE_SCREEN_ASCII_TXT);
  3982.                     break;
  3983.  
  3984.                 case DATATYPE_SCREENIMAGE:
  3985.  
  3986.                     Title = LocaleString(MSG_TERMMAIN_SAVE_SCREEN_IFF_TXT);
  3987.                     break;
  3988.             }
  3989.  
  3990.             BlockWindows();
  3991.  
  3992.             if(FileRequest = GetFile(Title,"","",DummyBuffer,NULL,TRUE,FALSE,FALSE,NULL,TRUE))
  3993.             {
  3994.                 FileName = DummyBuffer;
  3995.  
  3996.                 FreeAslRequest(FileRequest);
  3997.             }
  3998.  
  3999.             ReleaseWindows();
  4000.         }
  4001.  
  4002.         if(FileName)
  4003.         {
  4004.             switch(Index)
  4005.             {
  4006.                 case DATATYPE_TRANSLATIONS:
  4007.                 {
  4008.                     if(SendTable && ReceiveTable)
  4009.                     {
  4010.                         if(!SaveTranslationTables(FileName,SendTable,ReceiveTable))
  4011.                         {
  4012.                             Results[0] = RC_ERROR;
  4013.                             Results[1] = IoErr();
  4014.                         }
  4015.                         else
  4016.                         {
  4017.                             strcpy(LastTranslation,FileName);
  4018.  
  4019.                             TranslationChanged = FALSE;
  4020.                         }
  4021.                     }
  4022.                     else
  4023.                         Results[0] = RC_WARN;
  4024.                 }
  4025.  
  4026.                 break;
  4027.  
  4028.                 case DATATYPE_FUNCTIONKEYS:
  4029.                 {
  4030.                     if(!WriteIFFData(FileName,MacroKeys,sizeof(struct MacroKeys),ID_KEYS))
  4031.                     {
  4032.                         Results[0] = RC_ERROR;
  4033.                         Results[1] = IoErr();
  4034.                     }
  4035.                     else
  4036.                     {
  4037.                         strcpy(LastMacros,FileName);
  4038.  
  4039.                         MacroChanged = FALSE;
  4040.                     }
  4041.                 }
  4042.  
  4043.                 break;
  4044.  
  4045.                 case DATATYPE_CURSORKEYS:
  4046.                 {
  4047.                     if(!WriteIFFData(FileName,CursorKeys,sizeof(struct CursorKeys),ID_KEYS))
  4048.                     {
  4049.                         Results[0] = RC_ERROR;
  4050.                         Results[1] = IoErr();
  4051.                     }
  4052.                     else
  4053.                     {
  4054.                         strcpy(LastCursorKeys,FileName);
  4055.  
  4056.                         CursorKeysChanged = FALSE;
  4057.                     }
  4058.                 }
  4059.  
  4060.                 break;
  4061.  
  4062.                 case DATATYPE_FASTMACROS:
  4063.                 {
  4064.                     if(!SaveFastMacros(FileName))
  4065.                     {
  4066.                         Results[0] = RC_ERROR;
  4067.                         Results[1] = IoErr();
  4068.                     }
  4069.                     else
  4070.                     {
  4071.                         strcpy(LastFastMacros,FileName);
  4072.  
  4073.                         FastMacrosChanged = FALSE;
  4074.                     }
  4075.                 }
  4076.  
  4077.                 break;
  4078.  
  4079.                 case DATATYPE_HOTKEYS:
  4080.                 {
  4081.                     if(!WriteIFFData(FileName,&Hotkeys,sizeof(struct Hotkeys),ID_HOTK))
  4082.                     {
  4083.                         Results[0] = RC_ERROR;
  4084.                         Results[1] = IoErr();
  4085.                     }
  4086.                     else
  4087.                     {
  4088.                         strcpy(LastKeys,FileName);
  4089.  
  4090.                         HotkeysChanged = FALSE;
  4091.                     }
  4092.                 }
  4093.  
  4094.                 break;
  4095.  
  4096.                 case DATATYPE_SPEECH:
  4097.                 {
  4098.                     if(!WriteIFFData(FileName,&SpeechConfig,sizeof(struct SpeechConfig),ID_SPEK))
  4099.                     {
  4100.                         Results[0] = RC_ERROR;
  4101.                         Results[1] = IoErr();
  4102.                     }
  4103.                     else
  4104.                     {
  4105.                         strcpy(LastSpeech,FileName);
  4106.  
  4107.                         SpeechChanged = FALSE;
  4108.                     }
  4109.                 }
  4110.  
  4111.                 break;
  4112.  
  4113.                 case DATATYPE_SOUND:
  4114.                 {
  4115.                     if(!WriteIFFData(FileName,&SoundConfig,sizeof(struct SoundConfig),ID_SOUN))
  4116.                     {
  4117.                         Results[0] = RC_ERROR;
  4118.                         Results[1] = IoErr();
  4119.                     }
  4120.                     else
  4121.                     {
  4122.                         strcpy(LastSound,FileName);
  4123.  
  4124.                         SoundChanged = FALSE;
  4125.                     }
  4126.                 }
  4127.  
  4128.                 break;
  4129.  
  4130.                 case DATATYPE_BUFFER:
  4131.                 {
  4132.                     if(BufferLines && Lines)
  4133.                     {
  4134.                         BPTR SomeFile;
  4135.  
  4136.                         if(GetFileSize(FileName))
  4137.                         {
  4138.                             if(SomeFile = Open(FileName,MODE_READWRITE))
  4139.                             {
  4140.                                 if(Seek(SomeFile,0,OFFSET_END) == -1)
  4141.                                 {
  4142.                                     Close(SomeFile);
  4143.  
  4144.                                     SomeFile = NULL;
  4145.  
  4146.                                     SetIoErr(ERROR_SEEK_ERROR);
  4147.                                 }
  4148.                             }
  4149.                         }
  4150.                         else
  4151.                             SomeFile = Open(FileName,MODE_NEWFILE);
  4152.  
  4153.                         if(SomeFile)
  4154.                         {
  4155.                             LONG i,Len;
  4156.  
  4157.                                 /* Obtain the semaphore required
  4158.                                  * to gain access to the line buffer
  4159.                                  */
  4160.  
  4161.                             ObtainSemaphore(BufferSemaphore);
  4162.  
  4163.                             for(i = 0 ; i < Lines ; i++)
  4164.                             {
  4165.                                 Len = BufferLines[i][-1];
  4166.  
  4167.                                 if(Len)
  4168.                                 {
  4169.                                     if(FWrite(SomeFile,BufferLines[i],Len,1) != 1)
  4170.                                     {
  4171.                                         Results[0] = RC_ERROR;
  4172.                                         Results[1] = IoErr();
  4173.  
  4174.                                         break;
  4175.                                     }
  4176.                                 }
  4177.  
  4178.                                 if(FPrintf(SomeFile,"\n") < 1)
  4179.                                 {
  4180.                                     Results[0] = RC_ERROR;
  4181.                                     Results[1] = IoErr();
  4182.  
  4183.                                     break;
  4184.                                 }
  4185.                             }
  4186.  
  4187.                             ReleaseSemaphore(BufferSemaphore);
  4188.  
  4189.                             Close(SomeFile);
  4190.  
  4191.                             AddProtection(FileName,FIBF_EXECUTE);
  4192.  
  4193.                             if(Config -> MiscConfig -> CreateIcons)
  4194.                                 AddIcon(FileName,FILETYPE_TEXT,TRUE);
  4195.  
  4196.                             BufferChanged = FALSE;
  4197.                         }
  4198.                         else
  4199.                         {
  4200.                             Results[0] = RC_ERROR;
  4201.                             Results[1] = IoErr();
  4202.                         }
  4203.                     }
  4204.                     else
  4205.                     {
  4206.                         Results[0] = RC_ERROR;
  4207.                         Results[1] = TERMERROR_NO_DATA_TO_PROCESS;
  4208.                     }
  4209.                 }
  4210.  
  4211.                 break;
  4212.  
  4213.                 case DATATYPE_CONFIGURATION:
  4214.                 {
  4215.                     if(!WriteConfig(FileName,Config))
  4216.                     {
  4217.                         Results[0] = RC_ERROR;
  4218.                         Results[1] = IoErr();
  4219.                     }
  4220.                     else
  4221.                     {
  4222.                         strcpy(LastConfig,FileName);
  4223.  
  4224.                         ConfigChanged = FALSE;
  4225.                     }
  4226.                 }
  4227.  
  4228.                 break;
  4229.  
  4230.                 case DATATYPE_PHONEBOOK:
  4231.                 {
  4232.                     if(!SavePhonebook(FileName))
  4233.                     {
  4234.                         Results[0] = RC_ERROR;
  4235.                         Results[1] = IoErr();
  4236.                     }
  4237.                     else
  4238.                     {
  4239.                         strcpy(LastPhone,FileName);
  4240.  
  4241.                         PhonebookChanged = FALSE;
  4242.                     }
  4243.                 }
  4244.  
  4245.                 break;
  4246.  
  4247.                 case DATATYPE_SCREENTEXT:
  4248.                 {
  4249.                     if(RasterEnabled)
  4250.                     {
  4251.                         BPTR SomeFile;
  4252.  
  4253.                         if(GetFileSize(FileName))
  4254.                         {
  4255.                             if(SomeFile = Open(FileName,MODE_READWRITE))
  4256.                             {
  4257.                                 if(Seek(SomeFile,0,OFFSET_END) == -1)
  4258.                                 {
  4259.                                     Close(SomeFile);
  4260.  
  4261.                                     SomeFile = NULL;
  4262.  
  4263.                                     SetIoErr(ERROR_SEEK_ERROR);
  4264.                                 }
  4265.                             }
  4266.                         }
  4267.                         else
  4268.                             SomeFile = Open(FileName,MODE_NEWFILE);
  4269.  
  4270.                         if(SomeFile)
  4271.                         {
  4272.                             LONG     i,j;
  4273.                             UBYTE    *Buffer;
  4274.  
  4275.                             for(i = 0 ; i < RasterHeight ; i++)
  4276.                             {
  4277.                                 Buffer = &Raster[i * RasterWidth];
  4278.  
  4279.                                 j = LastColumn;
  4280.  
  4281.                                 while(j >= 0 && Buffer[j] == ' ')
  4282.                                     j--;
  4283.  
  4284.                                 if(j >= 0)
  4285.                                 {
  4286.                                     if(!FWrite(SomeFile,Buffer,j + 1,1))
  4287.                                     {
  4288.                                         Results[0] = RC_ERROR;
  4289.                                         Results[1] = IoErr();
  4290.  
  4291.                                         break;
  4292.                                     }
  4293.                                 }
  4294.  
  4295.                                 if(!FWrite(SomeFile,"\n",1,1))
  4296.                                 {
  4297.                                     Results[0] = RC_ERROR;
  4298.                                     Results[1] = IoErr();
  4299.  
  4300.                                     break;
  4301.                                 }
  4302.                             }
  4303.  
  4304.                             Close(SomeFile);
  4305.  
  4306.                             AddProtection(FileName,FIBF_EXECUTE);
  4307.  
  4308.                             if(Config -> MiscConfig -> CreateIcons)
  4309.                                 AddIcon(FileName,FILETYPE_TEXT,TRUE);
  4310.                         }
  4311.                         else
  4312.                         {
  4313.                             Results[0] = RC_ERROR;
  4314.                             Results[1] = IoErr();
  4315.                         }
  4316.                     }
  4317.                     else
  4318.                     {
  4319.                         Results[0] = RC_ERROR;
  4320.                         Results[1] = TERMERROR_NO_DATA_TO_PROCESS;
  4321.                     }
  4322.                 }
  4323.  
  4324.                 break;
  4325.  
  4326.                 case DATATYPE_SCREENIMAGE:
  4327.                 {
  4328.                     if(!SaveWindow(FileName,Window))
  4329.                     {
  4330.                         Results[0] = RC_ERROR;
  4331.                         Results[1] = IoErr();
  4332.                     }
  4333.                 }
  4334.  
  4335.                 break;
  4336.             }
  4337.         }
  4338.         else
  4339.             Results[0] = RC_WARN;
  4340.     }
  4341.  
  4342.     return(NULL);
  4343. }
  4344.  
  4345. STRPTR __regargs
  4346. RexxSave(struct RexxPkt *Pkt)
  4347. {
  4348.     enum    {    ARG_SAVE_FROM };
  4349.  
  4350.     Args[1] = Args[ARG_SAVE_FROM];
  4351.     Args[0] = NULL;
  4352.  
  4353.     return(RexxSaveAs(Pkt));
  4354. }
  4355.  
  4356. STRPTR __regargs
  4357. RexxSelect(struct RexxPkt *Pkt)
  4358. {
  4359.     enum    {    ARG_SELECT_NAME,ARG_SELECT_FROM,ARG_SELECT_NEXT,ARG_SELECT_PREVIOUS,
  4360.             ARG_SELECT_TOP,ARG_SELECT_BOTTOM };
  4361.  
  4362.     WORD Index;
  4363.  
  4364.     if((Index = ToList(Args[ARG_SELECT_FROM])) == -1)
  4365.     {
  4366.         Results[0] = RC_ERROR;
  4367.         Results[1] = TERMERROR_UNKNOWN_LIST;
  4368.     }
  4369.     else
  4370.     {
  4371.         if(Args[ARG_SELECT_NAME] && Index == GLIST_DIAL)
  4372.         {
  4373.             Results[0] = RC_ERROR;
  4374.             Results[1] = TERMERROR_DATA_TYPES_INCOMPATIBLE;
  4375.         }
  4376.         else
  4377.         {
  4378.             struct GenericList *List;
  4379.  
  4380.             List = GenericListTable[Index];
  4381.  
  4382.             if(Args[ARG_SELECT_NAME])
  4383.             {
  4384.                 STRPTR Buffer;
  4385.  
  4386.                 if(Buffer = CreateMatchBuffer(Args[ARG_SELECT_NAME]))
  4387.                 {
  4388.                     struct Node *Node,*NextNode;
  4389.  
  4390.                     ObtainSemaphore(&List -> ListSemaphore);
  4391.  
  4392.                     Node = (struct Node *)List -> ListHeader . mlh_Head;
  4393.  
  4394.                     while(NextNode = Node -> ln_Succ)
  4395.                     {
  4396.                         if(MatchBuffer(Buffer,Node -> ln_Name))
  4397.                         {
  4398.                             List -> ListNode = Node;
  4399.  
  4400.                             Node = NULL;
  4401.  
  4402.                             break;
  4403.                         }
  4404.  
  4405.                         Node = NextNode;
  4406.                     }
  4407.  
  4408.                     if(Node)
  4409.                         Results[0] = RC_WARN;
  4410.  
  4411.                     ReleaseSemaphore(&List -> ListSemaphore);
  4412.  
  4413.                     DeleteMatchBuffer(Buffer);
  4414.                 }
  4415.                 else
  4416.                 {
  4417.                     Results[0] = RC_ERROR;
  4418.                     Results[1] = ERROR_NO_FREE_STORE;
  4419.                 }
  4420.             }
  4421.             else
  4422.             {
  4423.                 if(Args[ARG_SELECT_NEXT])
  4424.                 {
  4425.                     if(!NextGenericListNode(List))
  4426.                     {
  4427.                         Results[0] = RC_WARN;
  4428.  
  4429.                         return(NULL);
  4430.                     }
  4431.                 }
  4432.  
  4433.                 if(Args[ARG_SELECT_PREVIOUS])
  4434.                 {
  4435.                     if(!PrevGenericListNode(List))
  4436.                     {
  4437.                         Results[0] = RC_WARN;
  4438.  
  4439.                         return(NULL);
  4440.                     }
  4441.                 }
  4442.  
  4443.                 if(Args[ARG_SELECT_TOP])
  4444.                 {
  4445.                     if(!FirstGenericListNode(List))
  4446.                     {
  4447.                         Results[0] = RC_WARN;
  4448.  
  4449.                         return(NULL);
  4450.                     }
  4451.                 }
  4452.  
  4453.                 if(Args[ARG_SELECT_BOTTOM])
  4454.                 {
  4455.                     if(!LastGenericListNode(List))
  4456.                     {
  4457.                         Results[0] = RC_WARN;
  4458.  
  4459.                         return(NULL);
  4460.                     }
  4461.                 }
  4462.             }
  4463.  
  4464.             ObtainSemaphore(&List -> ListSemaphore);
  4465.  
  4466.             if(List -> ListNode)
  4467.             {
  4468.                 if(Index != GLIST_DIAL)
  4469.                 {
  4470.                     struct Node    *Node = (struct Node *)List -> ListNode;
  4471.                     STRPTR         Result;
  4472.  
  4473.                     Result = CreateResult(Node -> ln_Name,Results);
  4474.  
  4475.                     ReleaseSemaphore(&List -> ListSemaphore);
  4476.  
  4477.                     return(Result);
  4478.                 }
  4479.             }
  4480.             else
  4481.                 Results[0] = RC_WARN;
  4482.  
  4483.             ReleaseSemaphore(&List -> ListSemaphore);
  4484.         }
  4485.     }
  4486.  
  4487.     return(NULL);
  4488. }
  4489.  
  4490. STRPTR __regargs
  4491. RexxSend(struct RexxPkt *Pkt)
  4492. {
  4493.     enum    {    ARG_SEND_NOECHO,ARG_SEND_LOCAL,ARG_SEND_BYTE,ARG_SEND_TEXT };
  4494.  
  4495.     if(Args[ARG_SEND_LOCAL])
  4496.     {
  4497.         if(!Args[ARG_SEND_NOECHO])
  4498.         {
  4499.             if(Args[ARG_SEND_TEXT])
  4500.                 ConsoleCommand(Args[ARG_SEND_TEXT]);
  4501.             else
  4502.             {
  4503.                 UBYTE Byte = *(LONG *)Args[ARG_SEND_BYTE];
  4504.  
  4505.                 ClearCursor();
  4506.  
  4507.                 if(Marking)
  4508.                     DropMarker();
  4509.  
  4510.                 ConProcess(&Byte,1);
  4511.  
  4512.                 DrawCursor();
  4513.             }
  4514.         }
  4515.     }
  4516.     else
  4517.     {
  4518.         if(Args[ARG_SEND_NOECHO])
  4519.             Quiet = TRUE;
  4520.  
  4521.         if(Args[ARG_SEND_TEXT])
  4522.             LocalRexxSerialCommand(Args[ARG_SEND_TEXT],Pkt);
  4523.         else
  4524.         {
  4525.             UBYTE Byte = *(LONG *)Args[ARG_SEND_BYTE];
  4526.  
  4527.             SerWrite(&Byte,1);
  4528.         }
  4529.  
  4530.         Quiet = FALSE;
  4531.     }
  4532.  
  4533.     return(NULL);
  4534. }
  4535.  
  4536. STRPTR __regargs
  4537. RexxSendBreak(struct RexxPkt *Pkt)
  4538. {
  4539.     if(WriteRequest)
  4540.     {
  4541.         BYTE OldStatus = Status;
  4542.  
  4543.         Status = STATUS_BREAKING;
  4544.  
  4545.         WriteRequest -> IOSer . io_Command = SDCMD_BREAK;
  4546.  
  4547.         BlockWindows();
  4548.  
  4549.         DoIO(WriteRequest);
  4550.  
  4551.         ReleaseWindows();
  4552.  
  4553.         Status = OldStatus;
  4554.     }
  4555.     else
  4556.         Results[0] = RC_WARN;
  4557.  
  4558.     return(NULL);
  4559. }
  4560.  
  4561. STRPTR __regargs
  4562. RexxSendFile(struct RexxPkt *Pkt)
  4563. {
  4564.     enum    {    ARG_SENDFILE_MODE,ARG_SENDFILE_NAMES };
  4565.  
  4566.     WORD Mode = TRANSFER_BINARY;
  4567.  
  4568.     if(Args[ARG_SENDFILE_MODE])
  4569.         Mode = ToMode(Args[ARG_SENDFILE_MODE]);
  4570.  
  4571.     if(Mode == -1)
  4572.     {
  4573.         Results[0] = RC_ERROR;
  4574.         Results[1] = ERROR_ACTION_NOT_KNOWN;
  4575.     }
  4576.     else
  4577.     {
  4578.         struct FileTransferInfo    *Info;
  4579.         LONG             FilesFound = 0;
  4580.  
  4581.         if(Info = AllocFileTransferInfo())
  4582.         {
  4583.             struct GenericList *List = GenericListTable[GLIST_UPLOAD];
  4584.  
  4585.             if(Args[ARG_SENDFILE_NAMES])
  4586.             {
  4587.                 struct FileInfoBlock *FileInfo;
  4588.  
  4589.                 if(FileInfo = (struct FileInfoBlock *)AllocDosObject(DOS_FIB,TAG_DONE))
  4590.                 {
  4591.                     STRPTR    *Names = (STRPTR *)Args[ARG_SENDFILE_NAMES];
  4592.                     BPTR     FileLock,NewDir,OldDir;
  4593.  
  4594.                     NewDir = NULL;
  4595.  
  4596.                     switch(Mode)
  4597.                     {
  4598.                         case TRANSFER_BINARY:
  4599.  
  4600.                             if(Config -> PathConfig -> BinaryUploadPath[0])
  4601.                                 NewDir = Lock(Config -> PathConfig -> BinaryUploadPath,ACCESS_READ);
  4602.  
  4603.                             break;
  4604.  
  4605.                         case TRANSFER_TEXT:
  4606.  
  4607.                             if(Config -> PathConfig -> TextUploadPath[0])
  4608.                                 NewDir = Lock(Config -> PathConfig -> TextUploadPath,ACCESS_READ);
  4609.  
  4610.                             break;
  4611.  
  4612.                         case TRANSFER_ASCII:
  4613.  
  4614.                             if(Config -> PathConfig -> ASCIIUploadPath[0])
  4615.                                 NewDir = Lock(Config -> PathConfig -> ASCIIUploadPath,ACCESS_READ);
  4616.  
  4617.                             break;
  4618.                     }
  4619.  
  4620.                     if(NewDir)
  4621.                         OldDir = CurrentDir(NewDir);
  4622.                     else
  4623.                         OldDir = NULL;
  4624.  
  4625.                     while(*Names && Results[0] == RC_OK)
  4626.                     {
  4627.                         if(FileLock = Lock(*Names,ACCESS_READ))
  4628.                         {
  4629.                             if(Examine(FileLock,FileInfo))
  4630.                             {
  4631.                                 if(FileInfo -> fib_DirEntryType < 0)
  4632.                                 {
  4633.                                     if(NameFromLock(FileLock,SharedBuffer,512))
  4634.                                     {
  4635.                                         if(AddFileTransferNode(Info,SharedBuffer,FileInfo -> fib_Size))
  4636.                                             FilesFound++;
  4637.                                         else
  4638.                                         {
  4639.                                             Results[0] = RC_ERROR;
  4640.                                             Results[1] = ERROR_NO_FREE_STORE;
  4641.                                         }
  4642.                                     }
  4643.                                     else
  4644.                                     {
  4645.                                         Results[0] = RC_ERROR;
  4646.                                         Results[1] = IoErr();
  4647.                                     }
  4648.                                 }
  4649.                                 else
  4650.                                 {
  4651.                                     Results[0] = RC_ERROR;
  4652.                                     Results[1] = ERROR_OBJECT_WRONG_TYPE;
  4653.                                 }
  4654.                             }
  4655.                             else
  4656.                             {
  4657.                                 Results[0] = RC_ERROR;
  4658.                                 Results[1] = IoErr();
  4659.                             }
  4660.  
  4661.                             UnLock(FileLock);
  4662.                         }
  4663.                         else
  4664.                         {
  4665.                             Results[0] = RC_ERROR;
  4666.                             Results[1] = IoErr();
  4667.                         }
  4668.  
  4669.                         Names++;
  4670.                     }
  4671.  
  4672.                     if(OldDir)
  4673.                         CurrentDir(OldDir);
  4674.  
  4675.                     if(NewDir)
  4676.                         UnLock(NewDir);
  4677.  
  4678.                     FreeDosObject(DOS_FIB,FileInfo);
  4679.                 }
  4680.                 else
  4681.                 {
  4682.                     Results[0] = RC_ERROR;
  4683.                     Results[1] = ERROR_NO_FREE_STORE;
  4684.                 }
  4685.             }
  4686.  
  4687.             ObtainSemaphore(&List -> ListSemaphore);
  4688.  
  4689.             if(List -> ListHeader . mlh_Head -> mln_Succ)
  4690.             {
  4691.                 struct Node        *Node = (struct Node *)List -> ListHeader . mlh_Head;
  4692.                 struct FileInfoBlock    *FileInfo;
  4693.                 BPTR             NewDir,OldDir;
  4694.  
  4695.                 NewDir = NULL;
  4696.  
  4697.                 switch(Mode)
  4698.                 {
  4699.                     case TRANSFER_BINARY:
  4700.  
  4701.                         if(Config -> PathConfig -> BinaryUploadPath[0])
  4702.                             NewDir = Lock(Config -> PathConfig -> BinaryUploadPath,ACCESS_READ);
  4703.  
  4704.                         break;
  4705.  
  4706.                     case TRANSFER_TEXT:
  4707.  
  4708.                         if(Config -> PathConfig -> TextUploadPath[0])
  4709.                             NewDir = Lock(Config -> PathConfig -> TextUploadPath,ACCESS_READ);
  4710.  
  4711.                         break;
  4712.  
  4713.                     case TRANSFER_ASCII:
  4714.  
  4715.                         if(Config -> PathConfig -> ASCIIUploadPath[0])
  4716.                             NewDir = Lock(Config -> PathConfig -> ASCIIUploadPath,ACCESS_READ);
  4717.  
  4718.                         break;
  4719.                 }
  4720.  
  4721.                 if(NewDir)
  4722.                     OldDir = CurrentDir(NewDir);
  4723.                 else
  4724.                     OldDir = NULL;
  4725.  
  4726.                 if(FileInfo = (struct FileInfoBlock *)AllocDosObject(DOS_FIB,TAG_DONE))
  4727.                 {
  4728.                     BPTR FileLock;
  4729.  
  4730.                     while(Node -> ln_Succ && Results[0] == RC_OK)
  4731.                     {
  4732.                         if(FileLock = Lock(Node -> ln_Name,ACCESS_READ))
  4733.                         {
  4734.                             if(Examine(FileLock,FileInfo))
  4735.                             {
  4736.                                 if(FileInfo -> fib_DirEntryType < 0)
  4737.                                 {
  4738.                                     if(NameFromLock(FileLock,SharedBuffer,512))
  4739.                                     {
  4740.                                         if(AddFileTransferNode(Info,SharedBuffer,FileInfo -> fib_Size))
  4741.                                             FilesFound++;
  4742.                                         else
  4743.                                         {
  4744.                                             Results[0] = RC_ERROR;
  4745.                                             Results[1] = ERROR_NO_FREE_STORE;
  4746.                                         }
  4747.                                     }
  4748.                                     else
  4749.                                     {
  4750.                                         Results[0] = RC_ERROR;
  4751.                                         Results[1] = IoErr();
  4752.                                     }
  4753.                                 }
  4754.                                 else
  4755.                                 {
  4756.                                     Results[0] = RC_ERROR;
  4757.                                     Results[1] = ERROR_OBJECT_WRONG_TYPE;
  4758.                                 }
  4759.                             }
  4760.                             else
  4761.                             {
  4762.                                 Results[0] = RC_ERROR;
  4763.                                 Results[1] = IoErr();
  4764.                             }
  4765.  
  4766.                             UnLock(FileLock);
  4767.                         }
  4768.                         else
  4769.                         {
  4770.                             Results[0] = RC_ERROR;
  4771.                             Results[1] = IoErr();
  4772.                         }
  4773.  
  4774.                         Node = Node -> ln_Succ;
  4775.                     }
  4776.  
  4777.                     if(OldDir)
  4778.                         CurrentDir(OldDir);
  4779.  
  4780.                     if(NewDir)
  4781.                         UnLock(NewDir);
  4782.  
  4783.                     FreeDosObject(DOS_FIB,FileInfo);
  4784.                 }
  4785.                 else
  4786.                 {
  4787.                     Results[0] = RC_ERROR;
  4788.                     Results[1] = ERROR_NO_FREE_STORE;
  4789.                 }
  4790.             }
  4791.  
  4792.             ReleaseSemaphore(&List -> ListSemaphore);
  4793.  
  4794.             if(Results[0] == RC_OK)
  4795.             {
  4796.                 BlockWindows();
  4797.  
  4798.                 if(FilesFound)
  4799.                 {
  4800.                     SortFileTransferInfo(Info);
  4801.  
  4802.                     FileTransferInfo = Info;
  4803.                 }
  4804.  
  4805.                 switch(Mode)
  4806.                 {
  4807.                     case TRANSFER_ASCII:
  4808.  
  4809.                         if(ChangeProtocol(Config -> TransferConfig -> ASCIIUploadLibrary))
  4810.                         {
  4811.                             BinaryTransfer = FALSE;
  4812.  
  4813.                             if(FilesFound)
  4814.                                 StartXprSendFromList(TRANSFER_ASCII,FALSE);
  4815.                             else
  4816.                                 StartXprSend(TRANSFER_ASCII,FALSE);
  4817.  
  4818.                             BinaryTransfer = TRUE;
  4819.  
  4820.                             LocalRexxSerialCommand(Config -> CommandConfig -> UploadMacro,NULL);
  4821.                         }
  4822.                         else
  4823.                         {
  4824.                             Results[0] = RC_ERROR;
  4825.                             Results[1] = ERROR_NO_FREE_STORE;
  4826.                         }
  4827.  
  4828.                         ResetProtocol();
  4829.  
  4830.                         break;
  4831.  
  4832.                     case TRANSFER_TEXT:
  4833.  
  4834.                         if(ChangeProtocol(Config -> TransferConfig -> TextUploadLibrary))
  4835.                         {
  4836.                             BinaryTransfer = FALSE;
  4837.  
  4838.                             if(FilesFound)
  4839.                                 StartXprSendFromList(TRANSFER_TEXT,FALSE);
  4840.                             else
  4841.                                 StartXprSend(TRANSFER_TEXT,FALSE);
  4842.  
  4843.                             BinaryTransfer = TRUE;
  4844.  
  4845.                             LocalRexxSerialCommand(Config -> CommandConfig -> UploadMacro,NULL);
  4846.                         }
  4847.                         else
  4848.                         {
  4849.                             Results[0] = RC_ERROR;
  4850.                             Results[1] = ERROR_NO_FREE_STORE;
  4851.                         }
  4852.  
  4853.                         ResetProtocol();
  4854.  
  4855.                         break;
  4856.  
  4857.                     case TRANSFER_BINARY:
  4858.  
  4859.                         if(ChangeProtocol(Config -> TransferConfig -> BinaryUploadLibrary))
  4860.                         {
  4861.                             BinaryTransfer = TRUE;
  4862.  
  4863.                             if(FilesFound)
  4864.                                 StartXprSendFromList(TRANSFER_BINARY,FALSE);
  4865.                             else
  4866.                                 StartXprSend(TRANSFER_BINARY,FALSE);
  4867.  
  4868.                             LocalRexxSerialCommand(Config -> CommandConfig -> UploadMacro,NULL);
  4869.                         }
  4870.                         else
  4871.                         {
  4872.                             Results[0] = RC_ERROR;
  4873.                             Results[1] = ERROR_NO_FREE_STORE;
  4874.                         }
  4875.  
  4876.                         ResetProtocol();
  4877.  
  4878.                         break;
  4879.                 }
  4880.  
  4881.                 if(TransferFailed)
  4882.                     Results[0] = RC_ERROR;
  4883.  
  4884.                 if(TransferAborted)
  4885.                     Results[0] = RC_WARN;
  4886.  
  4887.                 ReleaseWindows();
  4888.             }
  4889.             else
  4890.                 FreeFileTransferInfo(Info);
  4891.         }
  4892.         else
  4893.         {
  4894.             Results[0] = RC_ERROR;
  4895.             Results[1] = ERROR_NO_FREE_STORE;
  4896.         }
  4897.     }
  4898.  
  4899.     return(NULL);
  4900. }
  4901.  
  4902. STRPTR __regargs
  4903. RexxSpeak(struct RexxPkt *Pkt)
  4904. {
  4905.     enum    {    ARG_SPEAK_TEXT };
  4906.  
  4907.     if(SpeechConfig . Enabled && English)
  4908.         Say(Args[ARG_SPEAK_TEXT]);
  4909.     else
  4910.         Results[0] = RC_WARN;
  4911.  
  4912.     return(NULL);
  4913. }
  4914.  
  4915. STRPTR __regargs
  4916. RexxStopBits(struct RexxPkt *Pkt)
  4917. {
  4918.     enum    {    ARG_STOPBITS_0,ARG_STOPBITS_1 };
  4919.  
  4920.     BYTE Bits;
  4921.  
  4922.     if(Args[ARG_STOPBITS_0])
  4923.         Bits = 0;
  4924.  
  4925.     if(Args[ARG_STOPBITS_1])
  4926.         Bits = 1;
  4927.  
  4928.     if(Config -> SerialConfig -> StopBits != Bits)
  4929.     {
  4930.         Config -> SerialConfig -> StopBits = Bits;
  4931.  
  4932.         UpdateRequired = TRUE;
  4933.  
  4934.         ConfigChanged = TRUE;
  4935.     }
  4936.  
  4937.     return(NULL);
  4938. }
  4939.  
  4940. STRPTR __regargs
  4941. RexxTextBuffer(struct RexxPkt *Pkt)
  4942. {
  4943.     enum    {    ARG_TEXTBUFFER_LOCK,ARG_TEXTBUFFER_UNLOCK };
  4944.  
  4945.     if(Args[ARG_TEXTBUFFER_LOCK])
  4946.         BufferFrozen = TRUE;
  4947.  
  4948.     if(Args[ARG_TEXTBUFFER_UNLOCK])
  4949.         BufferFrozen = FALSE;
  4950.  
  4951.     CheckItem(MEN_FREEZE_BUFFER,BufferFrozen);
  4952.  
  4953.     return(NULL);
  4954. }
  4955.  
  4956. STRPTR __regargs
  4957. RexxTimeout(struct RexxPkt *Pkt)
  4958. {
  4959.     enum    {    ARG_TIMEOUT_SECONDS,ARG_TIMEOUT_OFF };
  4960.  
  4961.     if(Args[ARG_TIMEOUT_OFF])
  4962.         RexxTimeoutVal = 0;
  4963.     else
  4964.         RexxTimeoutVal = *(LONG *)Args[ARG_TIMEOUT_SECONDS];
  4965.  
  4966.     return(NULL);
  4967.  
  4968. }
  4969.  
  4970. STRPTR __regargs
  4971. RexxWait(struct RexxPkt *Pkt)
  4972. {
  4973.     enum    {    ARG_WAIT_NOECHO,ARG_WAIT_TEXT };
  4974.  
  4975.     ULONG         Signals;
  4976.     STRPTR         Result = NULL;
  4977.     BYTE         Echo;
  4978.     struct WaitNode    *WaitNode,
  4979.              Node;
  4980.     UBYTE         DummyBuffer[256];
  4981.  
  4982.     if(!ReadRequest || !WriteRequest)
  4983.     {
  4984.         Results[0] = RC_WARN;
  4985.  
  4986.         return(NULL);
  4987.     }
  4988.  
  4989.     if(Args[ARG_WAIT_NOECHO])
  4990.         Echo = FALSE;
  4991.     else
  4992.         Echo = TRUE;
  4993.  
  4994.     if(Args[ARG_WAIT_TEXT])
  4995.     {
  4996.         WORD i;
  4997.  
  4998.         memcpy(DummyBuffer,Args[ARG_WAIT_TEXT],255);
  4999.  
  5000.         DummyBuffer[255] = 0;
  5001.  
  5002.         for(i = 0 ; i < strlen(DummyBuffer) ; i++)
  5003.             DummyBuffer[i] = ToUpper(DummyBuffer[i]);
  5004.  
  5005.         memset(&Node,0,sizeof(struct WaitNode));
  5006.  
  5007.         Node . Node . ln_Name    = DummyBuffer;
  5008.         Node . Count        = 0;
  5009.  
  5010.         WaitNode = &Node;
  5011.     }
  5012.     else
  5013.     {
  5014.         if(!GenericListCount(GenericListTable[GLIST_WAIT]))
  5015.         {
  5016.             Results[0] = RC_ERROR;
  5017.             Results[1] = TERMERROR_LIST_IS_ALREADY_EMPTY;
  5018.  
  5019.             return(NULL);
  5020.         }
  5021.         else
  5022.         {
  5023.             WaitNode = (struct WaitNode *)GenericListTable[GLIST_WAIT] -> ListHeader . mlh_Head;
  5024.  
  5025.             while(WaitNode -> Node . ln_Succ)
  5026.             {
  5027.                 WaitNode -> Count = 0;
  5028.  
  5029.                 WaitNode = (struct WaitNode *)WaitNode -> Node . ln_Succ;
  5030.             }
  5031.  
  5032.             WaitNode = NULL;
  5033.         }
  5034.     }
  5035.  
  5036.     if(RexxTimeoutVal)
  5037.         StartTime(RexxTimeoutVal,0);
  5038.  
  5039.     WaitCount = 0;
  5040.  
  5041.     BlockWindows();
  5042.  
  5043.     if(Marking)
  5044.         DropMarker();
  5045.  
  5046.     ClearCursor();
  5047.  
  5048.     if(DataHold)
  5049.     {
  5050.         if(DataSize > 0)
  5051.         {
  5052.             if(Echo)
  5053.             {
  5054.                 ConProcess(DataHold,DataSize);
  5055.  
  5056.                 Status = STATUS_READY;
  5057.             }
  5058.  
  5059.             if(!Result)
  5060.                 Result = ScanNodeFilter(DataHold,DataSize,WaitNode);
  5061.         }
  5062.  
  5063.         DataHold = NULL;
  5064.  
  5065.         RestartSerial();
  5066.     }
  5067.  
  5068.     if(CheckIO(ReadRequest))
  5069.         Signals = SIG_SERIAL;
  5070.     else
  5071.         Signals = NULL;
  5072.  
  5073.     do
  5074.     {
  5075.         if(Signals & SIG_SERIAL)
  5076.         {
  5077.             if(!WaitIO(ReadRequest))
  5078.             {
  5079.                 LONG Length;
  5080.  
  5081.                 BytesIn++;
  5082.  
  5083.                 if(Echo)
  5084.                 {
  5085.                     ConProcess(ReadBuffer,1);
  5086.  
  5087.                     Status = STATUS_READY;
  5088.                 }
  5089.  
  5090.                 if(!Result)
  5091.                     Result = ScanNodeFilter(ReadBuffer,1,WaitNode);
  5092.  
  5093.                     /* Check how many bytes are still in
  5094.                      * the serial buffer.
  5095.                      */
  5096.  
  5097.                 WriteRequest -> IOSer . io_Command = SDCMD_QUERY;
  5098.  
  5099.                 DoIO(WriteRequest);
  5100.  
  5101.                 if(Length = WriteRequest -> IOSer . io_Actual)
  5102.                 {
  5103.                     if(Length > Config -> SerialConfig -> SerialBufferSize)
  5104.                         Length = Config -> SerialConfig -> SerialBufferSize;
  5105.  
  5106.                     if(Length > Config -> SerialConfig -> Quantum)
  5107.                         Length = Config -> SerialConfig -> Quantum;
  5108.  
  5109.                     ReadRequest -> IOSer . io_Command    = CMD_READ;
  5110.                     ReadRequest -> IOSer . io_Data        = ReadBuffer;
  5111.                     ReadRequest -> IOSer . io_Length    = Length;
  5112.  
  5113.                     if(!DoIO(ReadRequest))
  5114.                     {
  5115.                         BytesIn += Length;
  5116.  
  5117.                             /* Send the data to the console. */
  5118.  
  5119.                         if(Echo)
  5120.                         {
  5121.                             ConProcess(ReadBuffer,Length);
  5122.  
  5123.                             Status = STATUS_READY;
  5124.                         }
  5125.                     }
  5126.  
  5127.                     if(!Result)
  5128.                         Result = ScanNodeFilter(ReadBuffer,Length,WaitNode);
  5129.                 }
  5130.             }
  5131.  
  5132.             RestartSerial();
  5133.         }
  5134.  
  5135.         if(Signals & (SIG_BREAK | SIG_TIMER))
  5136.         {
  5137.             if(!Result)
  5138.                 Results[0] = RC_WARN;
  5139.  
  5140.             break;
  5141.         }
  5142.  
  5143.         if(!Result)
  5144.             Signals = Wait(SIG_SERIAL | SIG_TIMER | SIG_BREAK);
  5145.     }
  5146.     while(!Result);
  5147.  
  5148.     DrawCursor();
  5149.  
  5150.     ReleaseWindows();
  5151.  
  5152.     if(RexxTimeoutVal)
  5153.         StopTime();
  5154.  
  5155.     if(Result)
  5156.         return(CreateResult(Result,Results));
  5157.     else
  5158.         return(NULL);
  5159. }
  5160.  
  5161. STRPTR __regargs
  5162. RexxWindow(struct RexxPkt *Pkt)
  5163. {
  5164.     enum    {    ARG_WINDOW_NAMES,ARG_WINDOW_OPEN,ARG_WINDOW_CLOSE,ARG_WINDOW_ACTIVATE,
  5165.             ARG_WINDOW_MIN,ARG_WINDOW_MAX,ARG_WINDOW_FRONT,ARG_WINDOW_BACK,
  5166.             ARG_WINDOW_TOP,ARG_WINDOW_BOTTOM,ARG_WINDOW_UP,ARG_WINDOW_DOWN };
  5167.  
  5168.     STRPTR    *Names = (STRPTR *)Args[ARG_WINDOW_NAMES];
  5169.     WORD     Index;
  5170.  
  5171.     while(*Names)
  5172.     {
  5173.         if((Index = ToWindow(*Names++)) != -1)
  5174.         {
  5175.             if(Args[ARG_WINDOW_OPEN])
  5176.             {
  5177.                 switch(Index)
  5178.                 {
  5179.                     case WINDOWID_BUFFER:
  5180.  
  5181.                         if(!BufferProcess)
  5182.                             LaunchBuffer();
  5183.  
  5184.                         break;
  5185.  
  5186.                     case WINDOWID_REVIEW:
  5187.  
  5188.                         if(!ReviewWindow)
  5189.                             CreateReview();
  5190.  
  5191.                         break;
  5192.  
  5193.                     case WINDOWID_PACKET:
  5194.  
  5195.                         if(!PacketWindow)
  5196.                             CreatePacketWindow();
  5197.  
  5198.                         break;
  5199.  
  5200.                     case WINDOWID_FASTMACROS:
  5201.  
  5202.                         if(!FastWindow)
  5203.                             OpenFastWindow();
  5204.  
  5205.                         break;
  5206.  
  5207.                     case WINDOWID_STATUS:
  5208.  
  5209.                         if(!InfoWindow)
  5210.                             OpenInfoWindow();
  5211.  
  5212.                         break;
  5213.  
  5214.                     case WINDOWID_MAIN:
  5215.  
  5216.                         if(!IconTerminated)
  5217.                             IconTerminated = TRUE;
  5218.  
  5219.                         break;
  5220.                 }
  5221.             }
  5222.  
  5223.             if(Args[ARG_WINDOW_CLOSE])
  5224.             {
  5225.                 switch(Index)
  5226.                 {
  5227.                     case WINDOWID_BUFFER:
  5228.  
  5229.                         if(BufferProcess)
  5230.                         {
  5231.                             Forbid();
  5232.  
  5233.                             Signal(BufferProcess,SIG_KILL);
  5234.  
  5235.                             ClrSignal(SIG_HANDSHAKE);
  5236.  
  5237.                             Wait(SIG_HANDSHAKE);
  5238.  
  5239.                             Permit();
  5240.                         }
  5241.  
  5242.                         break;
  5243.  
  5244.                     case WINDOWID_REVIEW:
  5245.  
  5246.                         if(ReviewWindow)
  5247.                             DeleteReview();
  5248.  
  5249.                         break;
  5250.  
  5251.                     case WINDOWID_PACKET:
  5252.  
  5253.                         if(PacketWindow)
  5254.                             DeletePacketWindow(FALSE);
  5255.  
  5256.                         break;
  5257.  
  5258.                     case WINDOWID_FASTMACROS:
  5259.  
  5260.                         if(FastWindow)
  5261.                             CloseFastWindow();
  5262.  
  5263.                         break;
  5264.  
  5265.                     case WINDOWID_STATUS:
  5266.  
  5267.                         if(InfoWindow)
  5268.                             CloseInfoWindow();
  5269.  
  5270.                         break;
  5271.  
  5272.                     case WINDOWID_MAIN:
  5273.  
  5274.                         if(Window)
  5275.                             DoIconify = TRUE;
  5276.  
  5277.                         break;
  5278.                 }
  5279.             }
  5280.  
  5281.             if(Args[ARG_WINDOW_ACTIVATE])
  5282.             {
  5283.                 switch(Index)
  5284.                 {
  5285.                     case WINDOWID_BUFFER:
  5286.  
  5287.                         if(BufferProcess)
  5288.                             LaunchBuffer();
  5289.  
  5290.                         break;
  5291.  
  5292.                     case WINDOWID_REVIEW:
  5293.  
  5294.                         if(ReviewWindow)
  5295.                             BumpWindow(ReviewWindow);
  5296.  
  5297.                         break;
  5298.  
  5299.                     case WINDOWID_PACKET:
  5300.  
  5301.                         if(PacketWindow)
  5302.                             BumpWindow(PacketWindow);
  5303.  
  5304.                         break;
  5305.  
  5306.                     case WINDOWID_FASTMACROS:
  5307.  
  5308.                         if(FastWindow)
  5309.                             BumpWindow(FastWindow);
  5310.  
  5311.                         break;
  5312.  
  5313.                     case WINDOWID_STATUS:
  5314.  
  5315.                         if(InfoWindow)
  5316.                             BumpWindow(InfoWindow);
  5317.  
  5318.                         break;
  5319.  
  5320.                     case WINDOWID_MAIN:
  5321.  
  5322.                         if(Window)
  5323.                             BumpWindow(Window);
  5324.  
  5325.                         break;
  5326.                 }
  5327.             }
  5328.  
  5329.             if(Args[ARG_WINDOW_MIN])
  5330.             {
  5331.                 struct Window *SomeWindow = NULL;
  5332.  
  5333.                 switch(Index)
  5334.                 {
  5335.                     case WINDOWID_REVIEW:
  5336.  
  5337.                         SomeWindow = ReviewWindow;
  5338.                         break;
  5339.  
  5340.                     case WINDOWID_PACKET:
  5341.  
  5342.                         SomeWindow = PacketWindow;
  5343.                         break;
  5344.  
  5345.                     case WINDOWID_FASTMACROS:
  5346.  
  5347.                         SomeWindow = FastWindow;
  5348.                         break;
  5349.  
  5350.                     case WINDOWID_STATUS:
  5351.  
  5352.                         SomeWindow = InfoWindow;
  5353.                         break;
  5354.                 }
  5355.  
  5356.                 if(SomeWindow)
  5357.                     ChangeWindowBox(SomeWindow,SomeWindow -> LeftEdge,SomeWindow -> TopEdge,SomeWindow -> MinWidth,SomeWindow -> MinHeight);
  5358.             }
  5359.  
  5360.             if(Args[ARG_WINDOW_MAX])
  5361.             {
  5362.                 struct Window *SomeWindow = NULL;
  5363.  
  5364.                 switch(Index)
  5365.                 {
  5366.                     case WINDOWID_REVIEW:
  5367.  
  5368.                         SomeWindow = ReviewWindow;
  5369.                         break;
  5370.  
  5371.                     case WINDOWID_PACKET:
  5372.  
  5373.                         SomeWindow = PacketWindow;
  5374.                         break;
  5375.  
  5376.                     case WINDOWID_FASTMACROS:
  5377.  
  5378.                         SomeWindow = FastWindow;
  5379.                         break;
  5380.  
  5381.                     case WINDOWID_STATUS:
  5382.  
  5383.                         SomeWindow = InfoWindow;
  5384.                         break;
  5385.                 }
  5386.  
  5387.                 if(SomeWindow)
  5388.                     ChangeWindowBox(SomeWindow,0,0,SomeWindow -> MaxWidth,SomeWindow -> MaxHeight);
  5389.             }
  5390.  
  5391.             if(Args[ARG_WINDOW_FRONT])
  5392.             {
  5393.                 switch(Index)
  5394.                 {
  5395.                     case WINDOWID_BUFFER:
  5396.  
  5397.                         if(BufferProcess)
  5398.                             LaunchBuffer();
  5399.  
  5400.                         break;
  5401.  
  5402.                     case WINDOWID_REVIEW:
  5403.  
  5404.                         if(ReviewWindow)
  5405.                             WindowToFront(ReviewWindow);
  5406.  
  5407.                         break;
  5408.  
  5409.                     case WINDOWID_PACKET:
  5410.  
  5411.                         if(PacketWindow)
  5412.                             WindowToFront(PacketWindow);
  5413.  
  5414.                         break;
  5415.  
  5416.                     case WINDOWID_FASTMACROS:
  5417.  
  5418.                         if(FastWindow)
  5419.                             WindowToFront(FastWindow);
  5420.  
  5421.                         break;
  5422.  
  5423.                     case WINDOWID_STATUS:
  5424.  
  5425.                         if(InfoWindow)
  5426.                             WindowToFront(InfoWindow);
  5427.  
  5428.                         break;
  5429.  
  5430.                     case WINDOWID_MAIN:
  5431.  
  5432.                         if(Window)
  5433.                             WindowToFront(Window);
  5434.  
  5435.                         break;
  5436.                 }
  5437.             }
  5438.  
  5439.             if(Args[ARG_WINDOW_BACK])
  5440.             {
  5441.                 switch(Index)
  5442.                 {
  5443.                     case WINDOWID_REVIEW:
  5444.  
  5445.                         if(ReviewWindow)
  5446.                             WindowToBack(ReviewWindow);
  5447.  
  5448.                         break;
  5449.  
  5450.                     case WINDOWID_PACKET:
  5451.  
  5452.                         if(PacketWindow)
  5453.                             WindowToBack(PacketWindow);
  5454.  
  5455.                         break;
  5456.  
  5457.                     case WINDOWID_FASTMACROS:
  5458.  
  5459.                         if(FastWindow)
  5460.                             WindowToBack(FastWindow);
  5461.  
  5462.                         break;
  5463.  
  5464.                     case WINDOWID_STATUS:
  5465.  
  5466.                         if(InfoWindow)
  5467.                             WindowToBack(InfoWindow);
  5468.  
  5469.                         break;
  5470.  
  5471.                     case WINDOWID_MAIN:
  5472.  
  5473.                         if(Window)
  5474.                             WindowToBack(Window);
  5475.  
  5476.                         break;
  5477.                 }
  5478.             }
  5479.  
  5480.             if(Index == WINDOW_REVIEW && ReviewWindow)
  5481.             {
  5482.                 if(Args[ARG_WINDOW_TOP])
  5483.                     MoveReview(REVIEW_MOVE_TOP);
  5484.  
  5485.                 if(Args[ARG_WINDOW_BOTTOM])
  5486.                     MoveReview(REVIEW_MOVE_BOTTOM);
  5487.  
  5488.                 if(Args[ARG_WINDOW_UP])
  5489.                     MoveReview(REVIEW_MOVE_UP);
  5490.  
  5491.                 if(Args[ARG_WINDOW_DOWN])
  5492.                     MoveReview(REVIEW_MOVE_DOWN);
  5493.             }
  5494.         }
  5495.     }
  5496.  
  5497.     return(NULL);
  5498. }
  5499.  
  5500. STRPTR __regargs
  5501. RexxRX(struct RexxPkt *Pkt)
  5502. {
  5503.     enum    {    ARG_RX_CONSOLE,ARG_RX_ASYNC,ARG_RX_COMMAND };
  5504.  
  5505.     struct MsgPort    *RexxPort;
  5506.     BYTE         Eaten = FALSE;
  5507.  
  5508.     if(RexxPort = FindPort(RXSDIR))
  5509.     {
  5510.         struct MsgPort __aligned     SinglePort;
  5511.         struct RexxMsg            *HostMessage;
  5512.  
  5513.         InitSinglePort(&SinglePort);
  5514.  
  5515.         if(HostMessage = CreateRexxMsg(&SinglePort,"term",RexxPortName))
  5516.         {
  5517.             if(HostMessage -> rm_Args[0] = CreateArgstring(Args[ARG_RX_COMMAND],strlen(Args[ARG_RX_COMMAND])))
  5518.             {
  5519.                 HostMessage -> rm_Action = RXCOMM;
  5520.  
  5521.                 if(!GoodStream(NULL))
  5522.                     HostMessage -> rm_Action |= RXFF_NOIO;
  5523.  
  5524.                 if(Args[ARG_RX_ASYNC])
  5525.                 {
  5526.                     RexxPktCleanup(Pkt,NULL);
  5527.  
  5528.                     Eaten = TRUE;
  5529.                 }
  5530.  
  5531.                 Forbid();
  5532.  
  5533.                 PutMsg(RexxPort,HostMessage);
  5534.  
  5535.                 ClrSignal(SIGF_SINGLE);
  5536.  
  5537.                 WaitPort(&SinglePort);
  5538.  
  5539.                 Permit();
  5540.  
  5541.                 GetMsg(&SinglePort);
  5542.  
  5543.                 if(!Eaten)
  5544.                 {
  5545.                     Results[0] = HostMessage -> rm_Result1;
  5546.                     Results[1] = HostMessage -> rm_Result2;
  5547.                 }
  5548.             }
  5549.             else
  5550.             {
  5551.                 Results[0] = RC_ERROR;
  5552.                 Results[1] = ERR10_003;
  5553.             }
  5554.  
  5555.             DeleteRexxMsg(HostMessage);
  5556.         }
  5557.         else
  5558.         {
  5559.             Results[0] = RC_ERROR;
  5560.             Results[1] = ERR10_003;
  5561.         }
  5562.     }
  5563.     else
  5564.     {
  5565.         Results[0] = RC_ERROR;
  5566.         Results[1] = ERR10_013;
  5567.     }
  5568.  
  5569.     if(!Eaten)
  5570.         RexxPktCleanup(Pkt,NULL);
  5571.  
  5572.     return(NULL);
  5573. }
  5574.  
  5575. STRPTR __regargs
  5576. RexxExecTool(struct RexxPkt *Pkt)
  5577. {
  5578.     enum    {    ARG_EXECTOOL_CONSOLE,ARG_EXECTOOL_ASYNC,ARG_EXECTOOL_PORT,ARG_EXECTOOL_COMMAND };
  5579.  
  5580.     LONG     Error;
  5581.     UBYTE     CommandName[256],
  5582.          CommandArgs[256],
  5583.         *Index = Args[ARG_EXECTOOL_COMMAND];
  5584.     WORD     i;
  5585.     BYTE     Eaten = FALSE;
  5586.  
  5587.     while(*Index == ' ' || *Index == '\t')
  5588.         Index++;
  5589.  
  5590.     for(i = 0 ; Index[i] != ' ' && Index[i] != '\t' ; i++)
  5591.         CommandName[i] = Index[i];
  5592.  
  5593.     CommandName[i] = 0;
  5594.  
  5595.     Index += i;
  5596.  
  5597.     while(*Index == ' ' || *Index == '\t')
  5598.         Index++;
  5599.  
  5600.     if(Args[ARG_EXECTOOL_PORT])
  5601.         SPrintf(CommandArgs,"%s %s\n",Index,RexxPortName);
  5602.     else
  5603.         SPrintf(CommandArgs,"%s\n",Index);
  5604.  
  5605.     if(Args[ARG_EXECTOOL_ASYNC])
  5606.     {
  5607.         RexxPktCleanup(Pkt,NULL);
  5608.  
  5609.         Eaten = TRUE;
  5610.     }
  5611.  
  5612.     Error = SystemTags(CommandName,
  5613.         NP_Arguments,CommandArgs,
  5614.     TAG_DONE);
  5615.  
  5616.     if(!Eaten)
  5617.     {
  5618.         if(Error)
  5619.         {
  5620.             Results[0] = RC_ERROR;
  5621.             Results[1] = Error;
  5622.         }
  5623.  
  5624.         RexxPktCleanup(Pkt,NULL);
  5625.     }
  5626.  
  5627.     return(NULL);
  5628. }
  5629.